Skip to content

Commit 94c2560

Browse files
committed
More robust loop replacement
1 parent 6f5053b commit 94c2560

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pytest_asyncio/plugin.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ def pytest_fixture_setup(fixturedef, request):
9191
outcome = yield
9292
loop = outcome.get_result()
9393
policy = asyncio.get_event_loop_policy()
94-
old_loop = policy.get_event_loop()
95-
if old_loop is not loop:
96-
old_loop.close()
94+
try:
95+
old_loop = policy.get_event_loop()
96+
if old_loop is not loop:
97+
old_loop.close()
98+
except RuntimeError:
99+
# Swallow this, since it's probably bad event loop hygiene.
100+
pass
97101
policy.set_event_loop(loop)
98102
return
99103

0 commit comments

Comments
 (0)