Skip to content

Commit effc2e5

Browse files
Askaholicseifertm
authored andcommitted
Skip cleanup if the loop was closed in the test
1 parent 8a63a65 commit effc2e5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pytest_asyncio/plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,11 @@ def event_loop(request: "pytest.FixtureRequest") -> Iterator[asyncio.AbstractEve
491491
yield loop
492492
# Cleanup code copied from the implementation of asyncio.run()
493493
try:
494-
asyncio.runners._cancel_all_tasks(loop)
495-
loop.run_until_complete(loop.shutdown_asyncgens())
496-
if sys.version_info >= (3, 9):
497-
loop.run_until_complete(loop.shutdown_default_executor())
494+
if not loop.is_closed():
495+
asyncio.runners._cancel_all_tasks(loop)
496+
loop.run_until_complete(loop.shutdown_asyncgens())
497+
if sys.version_info >= (3, 9):
498+
loop.run_until_complete(loop.shutdown_default_executor())
498499
finally:
499500
loop.close()
500501
# Call the garbage collector to trigger ResourceWarning's as soon

0 commit comments

Comments
 (0)