MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / test_tool_timeout

Function test_tool_timeout

tests/lib/tools/test_session_runner.py:1890–1906  ·  view source on GitHub ↗

Tool that exceeds `TOOL_TIMEOUT` yields with `is_error=True` and a `"timed out"` message — distinct from the generic exception path.

(monkeypatch: pytest.MonkeyPatch)

Source from the content-addressed store, hash-verified

1888
1889@pytest.mark.asyncio()
1890async def test_tool_timeout(monkeypatch: pytest.MonkeyPatch) -> None:
1891 """Tool that exceeds `TOOL_TIMEOUT` yields with `is_error=True` and a
1892 `"timed out"` message — distinct from the generic exception path."""
1893 monkeypatch.setattr(session_runner_mod, "TOOL_TIMEOUT", 0.05)
1894
1895 async def slow(_input: dict[str, Any]) -> str:
1896 await asyncio.Event().wait() # never resolves
1897 return "never"
1898
1899 tool = _FakeTool("slow", slow)
1900 events = FakeAsyncEvents(stream_events=[_tool_use("tu_1", "slow", {}), _terminated()])
1901
1902 items = [item async for item in _run_with_fakes(events=events, tools=[tool])]
1903
1904 assert len(items) == 1
1905 assert items[0].is_error is True
1906 assert "timed out" in _result_text(items[0])
1907
1908
1909@pytest.mark.asyncio()

Callers

nothing calls this directly

Calls 6

_FakeToolClass · 0.85
FakeAsyncEventsClass · 0.85
_terminatedFunction · 0.85
_run_with_fakesFunction · 0.85
_result_textFunction · 0.85
_tool_useFunction · 0.70

Tested by

no test coverage detected