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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(tests): resolve MCP test isolation failures in parallel execution
Julio Quinteros Pro2e0a8b3cf892
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_debug.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_debug.pyindex 0fb299a57cd..de2037793c5 100644--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_debug.py+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_debug.py@@ -230,7 +230,7 @@ class TestWrapSendWithDebugHeaders:)message = {"type": "http.response.start", "status": 200, "headers": []}- asyncio.get_event_loop().run_until_complete(wrapped(message))+ asyncio.run(wrapped(message))assert len(captured) == 1headers = dict(captured[0]["headers"])@@ -247,6 +247,6 @@ class TestWrapSendWithDebugHeaders:)body_msg = {"type": "http.response.body", "body": b"hello"}- asyncio.get_event_loop().run_until_complete(wrapped(body_msg))+ asyncio.run(wrapped(body_msg))assert captured[0] == body_msgdiff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.pyindex 1a50cacd308..464e5238325 100644--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server_manager.py@@ -39,7 +39,16 @@ def _reload_mcp_manager_module():"litellm.proxy._experimental.mcp_server.mcp_server_manager"]importlib.reload(utils_module)- return importlib.reload(manager_module)+ reloaded = importlib.reload(manager_module)+ # After reload, server.py still holds a stale reference to the old+ # global_mcp_server_manager. Update it so tests that exercise server.py+ # functions (e.g. _get_tools_from_mcp_servers) use the fresh instance.+ server_module = sys.modules.get(+ "litellm.proxy._experimental.mcp_server.server"+ )+ if server_module is not None and hasattr(server_module, "global_mcp_server_manager"):+ server_module.global_mcp_server_manager = reloaded.global_mcp_server_manager+ return reloadedclass TestMCPServerManager:diff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.pyindex 452db3902c0..3bf783c09d4 100644--- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py+++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py@@ -1014,6 +1014,7 @@ async def test_add_litellm_metadata_from_request_headers():# Set up test loggerlitellm._turn_on_debug()test_logger = TestCustomLogger()+ original_callbacks = litellm.callbackslitellm.callbacks = [test_logger]# Prepare test data (ensure no streaming, add mock_response and api_key to route to litellm.acompletion)@@ -1098,7 +1099,9 @@ async def test_add_litellm_metadata_from_request_headers():SPEND_LOGS_METADATA = standard_logging_obj["metadata"]["spend_logs_metadata"]assert SPEND_LOGS_METADATA == dict(json.loads(headers["x-litellm-spend-logs-metadata"])), "spend_logs_metadata should be the same as the headers"-+ litellm.callbacks = original_callbacks++def test_get_internal_user_header_from_mapping_returns_expected_header():mappings = [