From 6b3a71e4c661ad1fb89a5dbde20f528f0a918c3b Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Wed, 24 Dec 2025 16:26:49 +0100 Subject: [PATCH] Detach the stack traces of the fixture errors and looptime errors Otherwise, the fixture errors were raised in the `yield`, which is itself under the `except RuntimeError` clause, and therefore the fixture error was considered connected to the RuntimeError, despite the latter is fully expected in this context. Signed-off-by: Sergey Vasilyev --- looptime/plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/looptime/plugin.py b/looptime/plugin.py index e654a61..c24b16e 100644 --- a/looptime/plugin.py +++ b/looptime/plugin.py @@ -265,12 +265,14 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> Any: try: running_loop = policy.get_event_loop() except RuntimeError: # a sync test with no loop set? not our business! - return (yield) + # The test error should come on its own later, not from the handler of the RuntimeError. + # Otherwise, the stacktraces are misleading, showing the RuntimeError for no reason. + running_loop = None elif 'event_loop' in funcargs: # pytest-asyncio<1.0.0 # The hook itself has NO "running" loop — because it is sync, not async. running_loop = funcargs['event_loop'] else: # not pytest-asyncio? not our business! - return (yield) + running_loop = None # The event loop is not patched? We are doomed to fail, so let it run somehow on its own. # This might happen if the custom event loop policy was set not by pytest-asyncio.