From 11fbb51a70774a13cd71099cb67f1178452c9a07 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 10 Feb 2026 20:48:30 +0400 Subject: [PATCH] fix(tests): Remove MCP conftest.py to fix session event loop conflict The MCP conftest.py with pytest hooks (pytest_addoption, pytest_collection_modifyitems) was disrupting pytest-asyncio's session event loop lifecycle, causing the SpinTestServer to be torn down before session-scoped oauth tests could run. Replace the conftest-based e2e gating with a simple pytestmark skipif in the test file itself. --- .../backend/backend/blocks/mcp/conftest.py | 29 ------------------- .../backend/backend/blocks/mcp/test_e2e.py | 7 ++++- 2 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 autogpt_platform/backend/backend/blocks/mcp/conftest.py diff --git a/autogpt_platform/backend/backend/blocks/mcp/conftest.py b/autogpt_platform/backend/backend/blocks/mcp/conftest.py deleted file mode 100644 index ee984832ff..0000000000 --- a/autogpt_platform/backend/backend/blocks/mcp/conftest.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Conftest for MCP block tests. - -Registers the e2e marker and --run-e2e CLI option so MCP end-to-end tests -(which hit real external servers) can be gated behind a flag. -""" - -import pytest - - -def pytest_configure(config: pytest.Config) -> None: - config.addinivalue_line("markers", "e2e: end-to-end tests requiring network") - - -def pytest_collection_modifyitems( - config: pytest.Config, items: list[pytest.Item] -) -> None: - """Skip e2e tests unless --run-e2e is passed.""" - if not config.getoption("--run-e2e", default=False): - skip_e2e = pytest.mark.skip(reason="need --run-e2e option to run") - for item in items: - if "e2e" in item.keywords: - item.add_marker(skip_e2e) - - -def pytest_addoption(parser: pytest.Parser) -> None: - parser.addoption( - "--run-e2e", action="store_true", default=False, help="run e2e tests" - ) diff --git a/autogpt_platform/backend/backend/blocks/mcp/test_e2e.py b/autogpt_platform/backend/backend/blocks/mcp/test_e2e.py index 6c85292929..d0bf0260a6 100644 --- a/autogpt_platform/backend/backend/blocks/mcp/test_e2e.py +++ b/autogpt_platform/backend/backend/blocks/mcp/test_e2e.py @@ -9,6 +9,7 @@ independently of the rest of the test suite (they require network access). """ import json +import os import pytest @@ -17,8 +18,12 @@ from backend.blocks.mcp.client import MCPClient # Public MCP server that requires no authentication OPENAI_DOCS_MCP_URL = "https://developers.openai.com/mcp" +# Skip all tests in this module unless RUN_E2E env var is set +pytestmark = pytest.mark.skipif( + not os.environ.get("RUN_E2E"), reason="set RUN_E2E=1 to run e2e tests" +) + -@pytest.mark.e2e class TestRealMCPServer: """Tests against the live OpenAI docs MCP server."""