Skip to content

Commit a94f91e

Browse files
committed
Merge branch 'master' into types
2 parents 14e16be + 0a3328f commit a94f91e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.rst

+1
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
- Added type annotations. `#198 <https://github.com/pytest-dev/pytest-asyncio/issues/198>`_
263264

264265
0.17.0 (22-01-13)

pytest_asyncio/plugin.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,13 @@ def pytest_fixture_post_finalizer(fixturedef: FixtureDef, request: SubRequest) -
249249
"""Called after fixture teardown"""
250250
if fixturedef.argname == "event_loop":
251251
policy = asyncio.get_event_loop_policy()
252-
# Clean up existing loop to avoid ResourceWarnings
253-
policy.get_event_loop().close()
252+
try:
253+
loop = policy.get_event_loop()
254+
except RuntimeError:
255+
loop = None
256+
if loop is not None:
257+
# Clean up existing loop to avoid ResourceWarnings
258+
loop.close()
254259
new_loop = policy.new_event_loop() # Replace existing event loop
255260
# Ensure subsequent calls to get_event_loop() succeed
256261
policy.set_event_loop(new_loop)

tests/test_event_loop_scope.py

+6
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)