Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code_puppy/agents/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ async def run_agent_task() -> Any:
except* Exception as other:
unexpected = _collect_exceptions(
other,
lambda e: not isinstance(
e, (asyncio.CancelledError, UsageLimitExceeded)
lambda e: (
not isinstance(e, (asyncio.CancelledError, UsageLimitExceeded))
),
)
for exc in unexpected:
Expand Down
20 changes: 16 additions & 4 deletions tests/plugins/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@
def pytest_configure(config):
"""Configure pytest with compatibility workarounds.

Pre-patch sys.modules to provide a mock ``mcp.types`` during collection.
This prevents a ValueError in pydantic's RootModel metaclass when MCP
is not installed in the test environment.
Pre-patch sys.modules to provide a mock ``mcp.types`` during collection,
but only when the real ``mcp`` package is not importable. Previously we
checked ``"mcp" not in sys.modules`` which is true on a clean start —
that installed MagicMocks for ``mcp.client`` etc. and then, when other
tests (e.g. ``tests/agents/test_compaction.py``) transitively imported
``pydantic_ai.mcp``, its ``from mcp.client.sse import sse_client`` blew
up with "'mcp.client' is not a package" because the MagicMock had no
``__path__``.

Real ``mcp`` is installed in this project's dev environment, so the
mock path is only needed in bare CI images. Probe with a real import
first; only fall back to mocks if that fails.
"""
if "mcp" not in sys.modules:
try:
import mcp # noqa: F401
import mcp.types # noqa: F401
except ImportError:
mcp_mock = MagicMock()
mcp_mock.types = MagicMock()
sys.modules["mcp"] = mcp_mock
Expand Down
Loading