mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-24 06:24:18 +02:00
Logcapture addition to test_server file (#1229)
This commit is contained in:
parent
9ea2798294
commit
126dd7b16a
1 changed files with 16 additions and 5 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue