Skip to content

Commit 77b6547

Browse files
committed
fix(tests): skip mcp server tests when mcp unavailable/incompatible
test_mcp_server.py imported fpb_mcp_server unconditionally, which hard- exits (sys.exit(1)) at import time when the optional mcp package is missing or its API is incompatible. mcp 2.0 removed the mcp.server.fastmcp import path, so a fresh CI install (unpinned 'pip install mcp' -> 2.0) crashed all 49 tests with SystemExit. Probe fpb_mcp_server importability once and apply a module-level pytest.mark.skipif, catching both ImportError (missing) and SystemExit (the module's own import guard). mcp 1.x still runs the full suite; mcp 2.0/missing now skips gracefully instead of failing. Change-Id: Icb488fc29307e610f60b5d84b48a07cfe72220fb
1 parent 1a18188 commit 77b6547

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎Tools/WebServer/tests/test_mcp_server.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,32 @@
66
import unittest
77
from unittest.mock import patch, MagicMock, PropertyMock
88

9+
import pytest
10+
911
# Add parent directory to path
1012
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1113

14+
# The MCP server module hard-exits (sys.exit(1)) at import time when the
15+
# optional `mcp` package is missing or its API is incompatible (e.g. the
16+
# `mcp.server.fastmcp` import path was removed in mcp 2.0). Probe
17+
# importability once and skip the whole module gracefully instead of letting
18+
# every test crash with SystemExit. This keeps CI green across mcp version
19+
# drift. Both ImportError (missing package) and SystemExit (the module's own
20+
# import guard) are treated as "mcp unavailable".
21+
try:
22+
import fpb_mcp_server as _fpb_mcp_server # noqa: F401
23+
24+
_MCP_AVAILABLE = True
25+
_MCP_SKIP_REASON = ""
26+
except (ImportError, SystemExit) as exc:
27+
_MCP_AVAILABLE = False
28+
_MCP_SKIP_REASON = (
29+
f"fpb_mcp_server unavailable (mcp not installed/incompatible): {exc!r}"
30+
)
31+
32+
# Module-level skip: pytest applies this to every test in the file.
33+
pytestmark = pytest.mark.skipif(not _MCP_AVAILABLE, reason=_MCP_SKIP_REASON)
34+
1235

1336
class TestCaptureCliOutput(unittest.TestCase):
1437
"""Test _capture_cli_output helper"""

0 commit comments

Comments
 (0)