Skip to content

Commit 338753b

Browse files
committed
Skip cleanup if the loop was closed in the test
1 parent 0d4b8f5 commit 338753b

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
@@ -487,10 +487,11 @@ def event_loop(request: "pytest.FixtureRequest") -> Iterator[asyncio.AbstractEve
487487
yield loop
488488
# Cleanup code copied from the implementation of asyncio.run()
489489
try:
490-
asyncio.runners._cancel_all_tasks(loop)
491-
loop.run_until_complete(loop.shutdown_asyncgens())
492-
if sys.version_info >= (3, 9):
493-
loop.run_until_complete(loop.shutdown_default_executor())
490+
if not loop.is_closed():
491+
asyncio.runners._cancel_all_tasks(loop)
492+
loop.run_until_complete(loop.shutdown_asyncgens())
493+
if sys.version_info >= (3, 9):
494+
loop.run_until_complete(loop.shutdown_default_executor())
494495
finally:
495496
loop.close()
496497
# Call the garbage collector to trigger ResourceWarning's as soon

0 commit comments

Comments
 (0)