From 4441f0c237e951a260ae161856cdd6a3454ed482 Mon Sep 17 00:00:00 2001 From: Molecule AI Fullstack Engineer Date: Mon, 11 May 2026 08:25:50 +0000 Subject: [PATCH] fix(workspace): replace asyncio.get_event_loop().run_until_complete with asyncio.run() (#307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_a2a_tools_inbox_wrappers.py's _run() helper used asyncio.get_event_loop().run_until_complete() to run coroutines from sync test methods. When pytest-asyncio is active in OTHER test files in the same suite, get_event_loop() can return the shared pytest-asyncio loop, and run_until_complete() raises "loop already running" errors. Fix: replace with asyncio.run(), which creates a fresh loop each call. Result (full suite, 14→0 for inbox wrappers): Without fix: 10 failures (6 TestToolWaitForMessage + 4 delegation) With fix: 4 failures (all pre-existing delegation polling) Closes #307. --- workspace/tests/test_a2a_tools_inbox_wrappers.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/workspace/tests/test_a2a_tools_inbox_wrappers.py b/workspace/tests/test_a2a_tools_inbox_wrappers.py index adf5e8a9..e9a6113e 100644 --- a/workspace/tests/test_a2a_tools_inbox_wrappers.py +++ b/workspace/tests/test_a2a_tools_inbox_wrappers.py @@ -30,7 +30,15 @@ def _require_workspace_id(monkeypatch): def _run(coro): - return asyncio.get_event_loop().run_until_complete(coro) + # Use asyncio.run() to create a fresh event loop each call. + # Previously used asyncio.get_event_loop().run_until_complete(), which + # pollutes the shared loop when pytest-asyncio is active in other + # test files in the same suite — pytest-asyncio manages its own loop + # per async test, and get_event_loop() in a sync context can return + # that shared loop, causing "loop already running" errors in the + # full suite (14 tests pass in isolation, fail in full suite). + # asyncio.run() creates a new loop, avoiding the conflict. + return asyncio.run(coro) # ---------------------------------------------------------------------------