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.
This commit is contained in:
Zamil Majdy
2026-02-10 20:48:30 +04:00
parent bb8b56c7de
commit 11fbb51a70
2 changed files with 6 additions and 30 deletions

View File

@@ -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"
)

View File

@@ -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."""