Skip to content

Commit

Permalink
refactor: test_async_fixtures_with_finalizer no longer trigger a Depr…
Browse files Browse the repository at this point in the history
…ecationWarning on Python 3.10.

The code was adjusted to use asyncio.get_event_loop_policy().get_event_loop() rather than the deprecated asyncio.get_event_loop().
Some additional comments were added to clarify the circumstances under which the test can fail.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm authored and Tinche committed May 30, 2021
1 parent 2751982 commit 1c283bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/async_fixtures/test_async_fixtures_with_finalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ async def port_afinalizer():
async def port_with_get_event_loop_finalizer(request, event_loop):
def port_finalizer(finalizer):
async def port_afinalizer():
# await task using loop provided by asyncio.get_event_loop()
# RuntimeError is raised if task is created on a different loop
# await task using current loop retrieved from the event loop policy
# RuntimeError is raised if task is created on a different loop.
# This can happen when pytest_fixture_setup does not set up the loop correctly,
# for example when policy.set_event_loop() is called with a wrong argument
await finalizer

asyncio.get_event_loop().run_until_complete(port_afinalizer())
current_loop = asyncio.get_event_loop_policy().get_event_loop()
current_loop.run_until_complete(port_afinalizer())

worker = asyncio.ensure_future(asyncio.sleep(0.2))
request.addfinalizer(functools.partial(port_finalizer, worker))
Expand Down

0 comments on commit 1c283bd

Please sign in to comment.