From 126dd7b16a47074fcc3c57ddba44e4c3cc97a521 Mon Sep 17 00:00:00 2001 From: Sourav Tripathy Date: Tue, 22 Jul 2025 23:19:49 +0530 Subject: [PATCH] Logcapture addition to test_server file (#1229) --- tests/server/test_server.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/server/test_server.py b/tests/server/test_server.py index 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, Any import httpx import pytest from fastapi import FastAPI from mcp import McpError from pydantic import Field +from pytest import LogCaptureFixture from fastmcp import Client, FastMCP from 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 logger with 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 above with caplog.at_level(logging.INFO):