test: standardize async tests on pytest-asyncio auto mode (#338)

* chore: add pytest-asyncio in auto mode

* test: migrate channel and stream tests to native async

Convert run_async() wrapper tests to plain 'async def test_*' under
pytest-asyncio auto mode. collect_events() in stream_v3_fakes becomes a
coroutine awaited at every call site.

* test: migrate command and model/middleware tests to native async

Convert run_async() wrappers (import, alias, and fixture forms) to plain
'async def test_*'. Multi-call tests merge onto one loop as sequential
awaits; none asserted on loop identity.

* test: migrate TUI, notifier, gateway, and session tests to native async

TUI/notifier/gateway files convert run_async wrappers to plain async
tests. test_sessions.py's unittest.TestCase classes move to
unittest.IsolatedAsyncioTestCase (pytest-asyncio does not await async
methods on plain TestCase; converting blindly would have made ~70 tests
silently vacuous). Its setUpClass keeps a one-shot asyncio.run() since
IsolatedAsyncioTestCase has no async class-level hook. TestLoadingWidget
in test_tui_widgets.py drops its TestCase base for the same reason.

* test: replace direct asyncio.run() calls with native async tests

Convert tests that called asyncio.run() (directly or via a local _run
helper) to plain 'async def test_*'; delete the local helpers.

* test: drop undeclared anyio markers and delete run_async helper

The @pytest.mark.anyio tests relied on anyio being a transitive dep of
httpx; auto-mode pytest-asyncio collects them natively. run_async() and
its fixture are unreferenced after the migration, so remove them —
pytest-asyncio's per-test loop teardown covers the pending-task
cancellation the helper existed for (verified: full suite runs with no
'Event loop is closed' errors or destroyed-task warnings).
This commit is contained in:
dinos
2026-07-08 20:37:48 +02:00
committed by GitHub
parent d2452c54d5
commit 690b903f85
61 changed files with 2869 additions and 3450 deletions
+10 -16
View File
@@ -149,40 +149,34 @@ class TestWrapToolCallAsync:
def setup_method(self):
self.mw = ToolErrorHandlerMiddleware()
@staticmethod
def _run(coro):
from tests.conftest import run_async
return run_async(coro)
def test_success_passes_through(self):
async def test_success_passes_through(self):
expected = ToolMessage(content="ok", tool_call_id="tc_001", name="t")
async def handler(req):
return expected
req = _make_request()
result = self._run(self.mw.awrap_tool_call(req, handler))
result = await self.mw.awrap_tool_call(req, handler)
assert result is expected
def test_command_passes_through(self):
async def test_command_passes_through(self):
cmd = Command(update={"messages": []})
async def handler(req):
return cmd
req = _make_request()
result = self._run(self.mw.awrap_tool_call(req, handler))
result = await self.mw.awrap_tool_call(req, handler)
assert result is cmd
def test_exception_returns_error_tool_message(self):
async def test_exception_returns_error_tool_message(self):
async def handler(req):
raise RuntimeError("MCP server timed out")
req = _make_request("slow_tool", "tc_async")
result = self._run(self.mw.awrap_tool_call(req, handler))
result = await self.mw.awrap_tool_call(req, handler)
assert isinstance(result, ToolMessage)
assert result.status == "error"
@@ -190,21 +184,21 @@ class TestWrapToolCallAsync:
assert result.name == "slow_tool"
assert "MCP server timed out" in result.content
def test_exception_does_not_propagate(self):
async def test_exception_does_not_propagate(self):
async def handler(req):
raise ConnectionError("connection lost")
req = _make_request()
result = self._run(self.mw.awrap_tool_call(req, handler))
result = await self.mw.awrap_tool_call(req, handler)
assert isinstance(result, ToolMessage)
def test_keyboard_interrupt_propagates(self):
async def test_keyboard_interrupt_propagates(self):
async def handler(req):
raise KeyboardInterrupt()
req = _make_request()
with pytest.raises(KeyboardInterrupt):
self._run(self.mw.awrap_tool_call(req, handler))
await self.mw.awrap_tool_call(req, handler)
# ---------------------------------------------------------------------------