From d6c3f39a34ebb28baa3c39df1d73879b5d4feb15 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 13 Jul 2026 11:40:15 +0200 Subject: [PATCH] dev-python/mcp: fix TOCTOU port collision in tests Attempt a blind fix for a collision during port assignment in parallel tests. Problematic tests are grouped, forcing them to run sequentially. Closes: https://bugs.gentoo.org/979158 Signed-off-by: Florian Albrechtskirchinger --- dev-python/mcp/mcp-1.28.1.ebuild | 37 ++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/dev-python/mcp/mcp-1.28.1.ebuild b/dev-python/mcp/mcp-1.28.1.ebuild index 55c859d537..82bd895fb8 100644 --- a/dev-python/mcp/mcp-1.28.1.ebuild +++ b/dev-python/mcp/mcp-1.28.1.ebuild @@ -51,15 +51,34 @@ EPYTEST_PLUGINS=( anyio inline-snapshot ) EPYTEST_XDIST=1 distutils_enable_tests pytest -EPYTEST_IGNORE=( - # Requires dev-python/pytest-examples which depends on missing Python - # bindings in dev-util/ruff::gentoo - tests/test_examples.py -) -EPYTEST_DESELECT=( - # Runs dev-python/uv and requires network access (v1.28.1) - tests/client/test_config.py::test_command_execution -) +src_prepare() { + distutils-r1_src_prepare + + # Fix TOCTOU port assignment issue + # https://bugs.gentoo.org/979158 + cat >> tests/conftest.py <<-EOF || die + + def pytest_collection_modifyitems(items): + for item in items: + if hasattr(item.module, "server_port"): + item.add_marker(pytest.mark.xdist_group(name="toctou_fix")) + EOF +} + +python_test() { + local EPYTEST_IGNORE=( + # Requires dev-python/pytest-examples which depends on missing Python + # bindings in dev-util/ruff::gentoo + tests/test_examples.py + ) + local EPYTEST_DESELECT=( + # Runs dev-python/uv and requires network access (v1.28.1) + tests/client/test_config.py::test_command_execution + ) + + epytest -m "xdist_group" --collect-only + epytest --dist=loadgroup +} pkg_postinst() { optfeature "colorized log output" dev-python/rich