Skip to content

Commit 201f6ec

Browse files
committed
[feat!] Async fixtures can no longer request the *event_loop* fixture.
Signed-off-by: Michael Seifert <[email protected]>
1 parent dac324c commit 201f6ec

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

docs/source/reference/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Changelog
33
=========
44

5+
0.23.0 (UNRELEASED)
6+
===================
7+
- BREAKING: Async fixtures can no longer request the *event_loop* fixture. Use *asyncio.get_running_loop()* instead.
8+
59
0.22.0 (2023-10-31)
610
===================
711
- Class-scoped and module-scoped event loops can be requested

pytest_asyncio/plugin.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,12 @@ def _synchronize_async_fixture(
269269
def _add_kwargs(
270270
func: Callable[..., Any],
271271
kwargs: Dict[str, Any],
272-
event_loop_fixture_id: str,
273-
event_loop: asyncio.AbstractEventLoop,
274272
request: SubRequest,
275273
) -> Dict[str, Any]:
276274
sig = inspect.signature(func)
277275
ret = kwargs.copy()
278276
if "request" in sig.parameters:
279277
ret["request"] = request
280-
if event_loop_fixture_id in sig.parameters:
281-
ret[event_loop_fixture_id] = event_loop
282278
return ret
283279

284280

@@ -309,10 +305,9 @@ def _asyncgen_fixture_wrapper(request: SubRequest, **kwargs: Any):
309305
func = _perhaps_rebind_fixture_func(
310306
fixture, request.instance, fixturedef.unittest
311307
)
312-
event_loop = kwargs.pop(event_loop_fixture_id)
313-
gen_obj = func(
314-
**_add_kwargs(func, kwargs, event_loop_fixture_id, event_loop, request)
315-
)
308+
kwargs.pop(event_loop_fixture_id)
309+
event_loop = asyncio.get_event_loop()
310+
gen_obj = func(**_add_kwargs(func, kwargs, request))
316311

317312
async def setup():
318313
res = await gen_obj.__anext__()
@@ -348,12 +343,11 @@ def _async_fixture_wrapper(request: SubRequest, **kwargs: Any):
348343
func = _perhaps_rebind_fixture_func(
349344
fixture, request.instance, fixturedef.unittest
350345
)
351-
event_loop = kwargs.pop(event_loop_fixture_id)
346+
kwargs.pop(event_loop_fixture_id)
347+
event_loop = asyncio.get_event_loop()
352348

353349
async def setup():
354-
res = await func(
355-
**_add_kwargs(func, kwargs, event_loop_fixture_id, event_loop, request)
356-
)
350+
res = await func(**_add_kwargs(func, kwargs, request))
357351
return res
358352

359353
return event_loop.run_until_complete(setup())

tests/test_explicit_event_loop_fixture_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def test_uses_fixture(emits_warning):
8989
)
9090
)
9191
result = pytester.runpytest("--asyncio-mode=strict")
92-
result.assert_outcomes(passed=1, warnings=1)
92+
result.assert_outcomes(errors=1, warnings=1)
9393
result.stdout.fnmatch_lines(
9494
['*is asynchronous and explicitly requests the "event_loop" fixture*']
9595
)
@@ -115,7 +115,7 @@ async def test_uses_fixture(emits_warning):
115115
)
116116
)
117117
result = pytester.runpytest("--asyncio-mode=strict")
118-
result.assert_outcomes(passed=1, warnings=1)
118+
result.assert_outcomes(errors=1, warnings=1)
119119
result.stdout.fnmatch_lines(
120120
['*is asynchronous and explicitly requests the "event_loop" fixture*']
121121
)

0 commit comments

Comments
 (0)