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
tests: patch MCP client mocks via module alias to avoid real network calls
Yuta Saitoab11ceff32e6
diff --git a/tests/mcp_tests/test_mcp_client_unit.py b/tests/mcp_tests/test_mcp_client_unit.pyindex 301234ec983..fcee3208be1 100644--- a/tests/mcp_tests/test_mcp_client_unit.py+++ b/tests/mcp_tests/test_mcp_client_unit.py@@ -10,6 +10,7 @@ from unittest.mock import AsyncMock, MagicMock, patch# Add the project root to the pathsys.path.insert(0, os.path.abspath("../../.."))+import litellm.experimental_mcp_client.client as mcp_client_modulefrom litellm.experimental_mcp_client.client import MCPClientfrom litellm.types.mcp import MCPAuth, MCPTransportfrom mcp.types import Tool as MCPTool, CallToolResult as MCPCallToolResult@@ -82,8 +83,8 @@ class TestMCPClientUnitTests:assert headers == {}@pytest.mark.asyncio- @patch("litellm.experimental_mcp_client.client.streamable_http_client")- @patch("litellm.experimental_mcp_client.client.ClientSession")+ @patch.object(mcp_client_module, "streamable_http_client")+ @patch.object(mcp_client_module, "ClientSession")async def test_run_with_session(self, mock_session_class, mock_transport):"""Test run_with_session establishes session with auth headers."""# Setup mocks@@ -117,8 +118,8 @@ class TestMCPClientUnitTests:mock_session_instance.initialize.assert_called_once()@pytest.mark.asyncio- @patch("litellm.experimental_mcp_client.client.streamable_http_client")- @patch("litellm.experimental_mcp_client.client.ClientSession")+ @patch.object(mcp_client_module, "streamable_http_client")+ @patch.object(mcp_client_module, "ClientSession")async def test_list_tools(self, mock_session_class, mock_transport):"""Test listing tools from the server."""# Setup mocks@@ -155,8 +156,8 @@ class TestMCPClientUnitTests:mock_session_instance.list_tools.assert_called_once()@pytest.mark.asyncio- @patch("litellm.experimental_mcp_client.client.streamable_http_client")- @patch("litellm.experimental_mcp_client.client.ClientSession")+ @patch.object(mcp_client_module, "streamable_http_client")+ @patch.object(mcp_client_module, "ClientSession")async def test_call_tool(self, mock_session_class, mock_transport):"""Test calling a tool."""from mcp.types import CallToolRequestParamsdiff --git a/tests/test_litellm/experimental_mcp_client/test_mcp_client.py b/tests/test_litellm/experimental_mcp_client/test_mcp_client.pyindex a03090d9c52..998f4156e93 100644--- a/tests/test_litellm/experimental_mcp_client/test_mcp_client.py+++ b/tests/test_litellm/experimental_mcp_client/test_mcp_client.py@@ -9,6 +9,7 @@ import pytest# Add the parent directory to the path so we can import litellmsys.path.insert(0, "../../../")+import litellm.experimental_mcp_client.client as mcp_client_modulefrom litellm.experimental_mcp_client.client import MCPClientfrom litellm.types.mcp import MCPStdioConfig, MCPTransport@@ -81,7 +82,7 @@ class TestMCPClient:assert call_args.env == {"DEBUG": "1"}@pytest.mark.asyncio- @patch("litellm.experimental_mcp_client.client.streamable_http_client")+ @patch.object(mcp_client_module, "streamable_http_client")@patch.dict(os.environ,{@@ -137,7 +138,7 @@ class TestMCPClient:await test_client.aclose()@pytest.mark.asyncio- @patch("litellm.experimental_mcp_client.client.sse_client")+ @patch.object(mcp_client_module, "sse_client")async def test_mcp_client_ssl_verify_parameter(self, mock_sse_client):"""Test that MCP client uses ssl_verify parameter when provided"""# Setup mocks@@ -188,7 +189,7 @@ class TestMCPClient:await test_client.aclose()@pytest.mark.asyncio- @patch("litellm.experimental_mcp_client.client.streamable_http_client")+ @patch.object(mcp_client_module, "streamable_http_client")async def test_mcp_client_ssl_verify_custom_path(self, mock_streamable_http_client):"""Test that MCP client uses custom CA bundle path from ssl_verify parameter"""# Setup mocks