Skip to content

Commit

Permalink
only fail on unclosed tasks with a running event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Nov 27, 2024
1 parent db1746f commit 7633bc3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,21 @@ def fail_test_on_unclosed_tasks(request: FixtureRequest):
by the end of the test.
"""

fail_count = request.session.testsfailed
try:
fail_count = request.session.testsfailed
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()

asyncio.set_event_loop(loop)
loop.set_debug(True)
asyncio.set_event_loop(loop)
loop.set_debug(True)

request.addfinalizer(
lambda: _error_and_kill_pending_tasks(
loop, request.node.name, request.session.testsfailed == fail_count
request.addfinalizer(
lambda: _error_and_kill_pending_tasks(
loop, request.node.name, request.session.testsfailed == fail_count
)
)
)
except RuntimeError as error:
if str(error) != "no running event loop":
raise error


@pytest.fixture(scope="function")
Expand Down

0 comments on commit 7633bc3

Please sign in to comment.