From ab11ceff32e686f8cbece135a5bf493c0f362a27 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 20 Jan 2026 12:31:27 +0900 Subject: [PATCH] tests: patch MCP client mocks via module alias to avoid real network calls --- tests/mcp_tests/test_mcp_client_unit.py | 13 +++++++------ .../experimental_mcp_client/test_mcp_client.py | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/mcp_tests/test_mcp_client_unit.py b/tests/mcp_tests/test_mcp_client_unit.py index 301234ec98..fcee3208be 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 path sys.path.insert(0, os.path.abspath("../../..")) +import litellm.experimental_mcp_client.client as mcp_client_module from litellm.experimental_mcp_client.client import MCPClient from litellm.types.mcp import MCPAuth, MCPTransport from 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 CallToolRequestParams diff --git a/tests/test_litellm/experimental_mcp_client/test_mcp_client.py b/tests/test_litellm/experimental_mcp_client/test_mcp_client.py index a03090d9c5..998f4156e9 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 litellm sys.path.insert(0, "../../../") +import litellm.experimental_mcp_client.client as mcp_client_module from litellm.experimental_mcp_client.client import MCPClient from 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