Skip to content

Commit 778962c

Browse files
committed
Make Agent MCP-related tests only run when mcp can be imported
1 parent 8203732 commit 778962c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tests/test_agent.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
ToolOutputSchema,
2525
)
2626
from pydantic_ai.agent import AgentRunResult
27-
from pydantic_ai.mcp import MCPServerStdio
2827
from pydantic_ai.messages import (
2928
BinaryContent,
3029
ImageUrl,
@@ -3442,13 +3441,18 @@ def test_deprecated_kwargs_still_work():
34423441
assert issubclass(w[0].category, DeprecationWarning)
34433442
assert '`result_retries` is deprecated' in str(w[0].message)
34443443

3445-
with warnings.catch_warnings(record=True) as w:
3446-
warnings.simplefilter('always')
3444+
try:
3445+
from pydantic_ai.mcp import MCPServerStdio
34473446

3448-
agent = Agent('test', mcp_servers=[MCPServerStdio('python', ['-m', 'tests.mcp_server'])]) # type: ignore[call-arg]
3449-
assert len(w) == 1
3450-
assert issubclass(w[0].category, DeprecationWarning)
3451-
assert '`mcp_servers` is deprecated' in str(w[0].message)
3447+
with warnings.catch_warnings(record=True) as w:
3448+
warnings.simplefilter('always')
3449+
3450+
agent = Agent('test', mcp_servers=[MCPServerStdio('python', ['-m', 'tests.mcp_server'])]) # type: ignore[call-arg]
3451+
assert len(w) == 1
3452+
assert issubclass(w[0].category, DeprecationWarning)
3453+
assert '`mcp_servers` is deprecated' in str(w[0].message)
3454+
except ImportError:
3455+
pass
34523456

34533457

34543458
def test_deprecated_kwargs_mixed_valid_invalid():
@@ -3604,6 +3608,11 @@ async def test_reentrant_context_manager():
36043608

36053609

36063610
def test_set_mcp_sampling_model():
3611+
try:
3612+
from pydantic_ai.mcp import MCPServerStdio
3613+
except ImportError:
3614+
return
3615+
36073616
test_model = TestModel()
36083617
server1 = MCPServerStdio('python', ['-m', 'tests.mcp_server'])
36093618
server2 = MCPServerStdio('python', ['-m', 'tests.mcp_server'], sampling_model=test_model)

0 commit comments

Comments
 (0)