π The fast, Pythonic way to build MCP servers and clients.
Logcapture addition to test_server file (#1229)
Sourav Tripathy126dd7b16a47
diff --git a/tests/server/test_server.py b/tests/server/test_server.pyindex dd4aad160..0bf13df0c 100644--- a/tests/server/test_server.py+++ b/tests/server/test_server.py@@ -1,11 +1,12 @@import logging-from typing import Annotated+from typing import Annotated, Anyimport httpximport pytestfrom fastapi import FastAPIfrom mcp import McpErrorfrom pydantic import Field+from pytest import LogCaptureFixturefrom fastmcp import Client, FastMCPfrom fastmcp.exceptions import NotFoundError@@ -1402,7 +1403,10 @@ class TestOpenAPIExperimentalFeatureFlag:return httpx.AsyncClient(base_url="https://api.example.com")def test_from_openapi_uses_legacy_by_default_and_logs_message(- self, simple_openapi_spec, mock_client, caplog+ self,+ simple_openapi_spec: dict[str, Any],+ mock_client: httpx.AsyncClient,+ caplog: LogCaptureFixture,):"""Test that from_openapi uses legacy parser by default and emits log message."""# Capture all logs at INFO level and above using FastMCP's logger@@ -1429,7 +1433,10 @@ class TestOpenAPIExperimentalFeatureFlag:)def test_from_openapi_uses_experimental_with_flag_and_no_log(- self, simple_openapi_spec, mock_client, caplog+ self,+ simple_openapi_spec: dict[str, Any],+ mock_client: httpx.AsyncClient,+ caplog: LogCaptureFixture,):"""Test that from_openapi uses experimental parser with flag and emits no log."""# Capture all logs at INFO level and above@@ -1451,7 +1458,9 @@ class TestOpenAPIExperimentalFeatureFlag:]assert len(legacy_log_messages) == 0- def test_from_fastapi_uses_legacy_by_default_and_logs_message(self, caplog):+ def test_from_fastapi_uses_legacy_by_default_and_logs_message(+ self, caplog: LogCaptureFixture+ ):"""Test that from_fastapi uses legacy parser by default and emits log message."""# Capture all logs at INFO level and above using FastMCP's loggerwith caplog_for_fastmcp(caplog), caplog.at_level(logging.INFO):@@ -1481,7 +1490,9 @@ class TestOpenAPIExperimentalFeatureFlag:in legacy_log_messages[0].message)- def test_from_fastapi_uses_experimental_with_flag_and_no_log(self, caplog):+ def test_from_fastapi_uses_experimental_with_flag_and_no_log(+ self, caplog: LogCaptureFixture+ ):"""Test that from_fastapi uses experimental parser with flag and emits no log."""# Capture all logs at INFO level and abovewith caplog.at_level(logging.INFO):