Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test: isolate global MCP registry and pin savings tests to bundled cost map

Devin AI5c7e6b80c9e4
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py b/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py
index b477bf3f406..c559e023c47 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/conftest.py
@@ -2,6 +2,37 @@ import os
import pytest
+from litellm.proxy._experimental.mcp_server.mcp_server_manager import (
+ global_mcp_server_manager,
+)
+
+
[email protected](autouse=True)
+def _hermetic_mcp_server_registry():
+ """Snapshot and restore the global manager's server-registry state around every test.
+
+ ``global_mcp_server_manager`` is a module-global singleton, and many tests in this
+ package seed ``registry``/``config_mcp_servers`` (or clear them) without cleaning up.
+ In a shared CI shard the leaked entries poison later tests in the same worker, e.g.
+ the ``all_proxy_servers`` sentinel expansion in ``auth/`` suddenly sees a bridge
+ server registered by a discovery test, so the outcome depends on xdist scheduling.
+ Restoring the state here makes ordering irrelevant.
+ """
+ saved_registry = dict(global_mcp_server_manager.registry)
+ saved_config_servers = dict(global_mcp_server_manager.config_mcp_servers)
+ saved_tool_mapping = dict(global_mcp_server_manager.tool_name_to_mcp_server_name_mapping)
+ saved_oauth_slots = global_mcp_server_manager._oauth_discovery_slots
+ try:
+ yield
+ finally:
+ global_mcp_server_manager.registry.clear()
+ global_mcp_server_manager.registry.update(saved_registry)
+ global_mcp_server_manager.config_mcp_servers.clear()
+ global_mcp_server_manager.config_mcp_servers.update(saved_config_servers)
+ global_mcp_server_manager.tool_name_to_mcp_server_name_mapping.clear()
+ global_mcp_server_manager.tool_name_to_mcp_server_name_mapping.update(saved_tool_mapping)
+ global_mcp_server_manager._oauth_discovery_slots = saved_oauth_slots
+
@pytest.fixture(autouse=True)
def _hermetic_server_root_path():
diff --git a/tests/test_litellm/proxy/spend_tracking/test_savings.py b/tests/test_litellm/proxy/spend_tracking/test_savings.py
index c3297ee6ae9..7dd18587df3 100644
--- a/tests/test_litellm/proxy/spend_tracking/test_savings.py
+++ b/tests/test_litellm/proxy/spend_tracking/test_savings.py
@@ -14,6 +14,8 @@ from litellm.proxy.spend_tracking.savings import (
from litellm.router import Router
from litellm.types.utils import Usage
+pytestmark = pytest.mark.usefixtures("local_model_cost_map")
+
def _anthropic_costs(model: str) -> tuple[float, float]:
info = litellm.get_model_info(model=model, custom_llm_provider="anthropic")