tests: patch MCP client mocks via module alias to avoid real network calls
This commit is contained in:
parent
7d7b78a53d
commit
ab11ceff32
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user