Resolve FastMCP settings before lifecycle tests

This commit is contained in:
Patrick Buckley
2026-08-11 21:36:37 -07:00
parent 8517b42ec1
commit 2b51b2f8fa
2 changed files with 19 additions and 0 deletions
+5
View File
@@ -108,6 +108,11 @@ markers = [
"e2e_recovery: opt-in end-to-end SSE recovery harness (real server + real SSE consumers, scripted provider — NOT live, no LLM backend needed); tens of seconds each. CI lanes run ``-m 'not live and not e2e_recovery'``; select with ``-m e2e_recovery``.",
]
filterwarnings = [
# The MCP v1 FastMCP integration fixture rebuilds its incomplete generic
# Settings model before construction. Keep the new pydantic-settings 2.15
# diagnostic fatal so removing that compatibility step cannot regress
# into a warning hidden in the full-suite summary.
"error:Field 'lifespan' has an incomplete definition",
# mcp v1 deprecates streamablehttp_client for an entry point whose call
# shape only settles in v2 — adoption rides the deliberate v2 migration
# (pin capped <2); silence exactly this message until then.
+14
View File
@@ -15,6 +15,20 @@ from unittest.mock import MagicMock
import pytest
def pytest_sessionstart(session: pytest.Session) -> None:
"""Resolve MCP v1's generic FastMCP settings model for test servers.
MCP 1.29.0 defines ``Settings`` before ``FastMCP``, so its ``lifespan``
annotation remains an unresolved forward reference after import. Rebuild
once, after the module is fully loaded, before any integration fixture
constructs a FastMCP server. Pydantic's public hook is a no-op once the SDK
ships a complete model.
"""
from mcp.server.fastmcp.server import Settings as FastMCPSettings
FastMCPSettings.model_rebuild()
def stop_loop_thread(loop: asyncio.AbstractEventLoop, thread: threading.Thread) -> None:
"""Fully tear down a ``loop.run_forever``-in-a-thread test loop.