Skip to content

Commit 87ef797

Browse files
committed
Merge branch 'master' into relax-config-type
2 parents 1b18f03 + 0a3328f commit 87ef797

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ Changelog
259259
0.17.1 (UNRELEASED)
260260
~~~~~~~~~~~~~~~~~~~
261261
- Fixes a bug that prevents async Hypothesis tests from working without explicit ``asyncio`` marker when ``--asyncio-mode=auto`` is set. `#258 <https://github.com/pytest-dev/pytest-asyncio/issues/258>`_
262+
- Fixed a bug that closes the default event loop if the loop doesn't exist `#257 <https://github.com/pytest-dev/pytest-asyncio/issues/257>`_
262263
- Relax ``asyncio_mode`` type definition; it allows to support pytest 5.4+. `#262 <https://github.com/pytest-dev/pytest-asyncio/issues/262>`_
263264

264265
0.17.0 (22-01-13)

pytest_asyncio/plugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,13 @@ def pytest_fixture_post_finalizer(fixturedef, request):
168168
"""Called after fixture teardown"""
169169
if fixturedef.argname == "event_loop":
170170
policy = asyncio.get_event_loop_policy()
171-
# Clean up existing loop to avoid ResourceWarnings
172-
policy.get_event_loop().close()
171+
try:
172+
loop = policy.get_event_loop()
173+
except RuntimeError:
174+
loop = None
175+
if loop is not None:
176+
# Clean up existing loop to avoid ResourceWarnings
177+
loop.close()
173178
new_loop = policy.new_event_loop() # Replace existing event loop
174179
# Ensure subsequent calls to get_event_loop() succeed
175180
policy.set_event_loop(new_loop)

tests/test_event_loop_scope.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ def test_3():
2929
current_loop = asyncio.get_event_loop_policy().get_event_loop()
3030
# Now the event loop from test_2 should have been cleaned up
3131
assert loop is not current_loop
32+
33+
34+
def test_4(event_loop):
35+
# If a test sets the loop to None -- pytest_fixture_post_finalizer()
36+
# still should work
37+
asyncio.get_event_loop_policy().set_event_loop(None)

0 commit comments

Comments
 (0)