Skip to content

Commit

Permalink
More robust loop replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche committed Apr 19, 2021
1 parent 6f5053b commit 94c2560
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ def pytest_fixture_setup(fixturedef, request):
outcome = yield
loop = outcome.get_result()
policy = asyncio.get_event_loop_policy()
old_loop = policy.get_event_loop()
if old_loop is not loop:
old_loop.close()
try:
old_loop = policy.get_event_loop()
if old_loop is not loop:
old_loop.close()
except RuntimeError:
# Swallow this, since it's probably bad event loop hygiene.
pass
policy.set_event_loop(loop)
return

Expand Down

0 comments on commit 94c2560

Please sign in to comment.