Skip to content

Commit 1c283bd

Browse files
seifertmTinche
authored andcommitted
refactor: test_async_fixtures_with_finalizer no longer trigger a DeprecationWarning 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 <[email protected]>
1 parent 2751982 commit 1c283bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/async_fixtures/test_async_fixtures_with_finalizer.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ async def port_afinalizer():
4444
async def port_with_get_event_loop_finalizer(request, event_loop):
4545
def port_finalizer(finalizer):
4646
async def port_afinalizer():
47-
# await task using loop provided by asyncio.get_event_loop()
48-
# RuntimeError is raised if task is created on a different loop
47+
# await task using current loop retrieved from the event loop policy
48+
# RuntimeError is raised if task is created on a different loop.
49+
# This can happen when pytest_fixture_setup does not set up the loop correctly,
50+
# for example when policy.set_event_loop() is called with a wrong argument
4951
await finalizer
5052

51-
asyncio.get_event_loop().run_until_complete(port_afinalizer())
53+
current_loop = asyncio.get_event_loop_policy().get_event_loop()
54+
current_loop.run_until_complete(port_afinalizer())
5255

5356
worker = asyncio.ensure_future(asyncio.sleep(0.2))
5457
request.addfinalizer(functools.partial(port_finalizer, worker))

0 commit comments

Comments
 (0)