Skip to content

Commit 667a4e4

Browse files
committed
refactor: Async fixtures no longer depend on a node's StashKey to retrieve the name of the scoped event loop fixture.
1 parent b0f9cc0 commit 667a4e4

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

pytest_asyncio/plugin.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Literal,
2929
TypeVar,
3030
Union,
31+
cast,
3132
overload,
3233
)
3334

@@ -396,21 +397,13 @@ async def setup():
396397
def _get_event_loop_fixture_id_for_async_fixture(
397398
request: FixtureRequest, func: Any
398399
) -> str:
399-
default_loop_scope = request.config.getini("asyncio_default_fixture_loop_scope")
400+
default_loop_scope = cast(
401+
_ScopeName, request.config.getini("asyncio_default_fixture_loop_scope")
402+
)
400403
loop_scope = (
401404
getattr(func, "_loop_scope", None) or default_loop_scope or request.scope
402405
)
403-
if loop_scope == "function":
404-
event_loop_fixture_id = "_function_event_loop"
405-
else:
406-
event_loop_node = _retrieve_scope_root(request._pyfuncitem, loop_scope)
407-
event_loop_fixture_id = event_loop_node.stash.get(
408-
# Type ignored because of non-optimal mypy inference.
409-
_event_loop_fixture_id, # type: ignore[arg-type]
410-
"",
411-
)
412-
assert event_loop_fixture_id
413-
return event_loop_fixture_id
406+
return f"_{loop_scope}_event_loop"
414407

415408

416409
def _create_task_in_context(

0 commit comments

Comments
 (0)