Skip to content

Commit ba324ef

Browse files
committed
refactor: _wrap_asyncgen_fixture receives the fixture function rather than the FixtureDef.
1 parent 1a83fb0 commit ba324ef

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pytest_asyncio/plugin.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Iterator,
2222
Sequence,
2323
)
24-
from types import CoroutineType
24+
from types import AsyncGeneratorType, CoroutineType
2525
from typing import (
2626
Any,
2727
Callable,
@@ -267,7 +267,7 @@ def _preprocess_async_fixtures(
267267
def _synchronize_async_fixture(fixturedef: FixtureDef) -> None:
268268
"""Wraps the fixture function of an async fixture in a synchronous function."""
269269
if inspect.isasyncgenfunction(fixturedef.func):
270-
fixturedef.func = _wrap_asyncgen_fixture(fixturedef) # type: ignore[misc]
270+
fixturedef.func = _wrap_asyncgen_fixture(fixturedef.func) # type: ignore[misc]
271271
elif inspect.iscoroutinefunction(fixturedef.func):
272272
fixturedef.func = _wrap_async_fixture(fixturedef.func) # type: ignore[misc]
273273

@@ -300,12 +300,15 @@ def _perhaps_rebind_fixture_func(func: _T, instance: Any | None) -> _T:
300300
return func
301301

302302

303-
def _wrap_asyncgen_fixture(fixturedef: FixtureDef) -> Callable:
304-
fixture = fixturedef.func
303+
AsyncGenFixtureYieldType = TypeVar("AsyncGenFixtureYieldType")
305304

306-
@functools.wraps(fixture)
305+
306+
def _wrap_asyncgen_fixture(
307+
fixture_function: Callable[..., AsyncGeneratorType[AsyncGenFixtureYieldType, Any]],
308+
) -> Callable[..., AsyncGenFixtureYieldType]:
309+
@functools.wraps(fixture_function)
307310
def _asyncgen_fixture_wrapper(request: FixtureRequest, **kwargs: Any):
308-
func = _perhaps_rebind_fixture_func(fixture, request.instance)
311+
func = _perhaps_rebind_fixture_func(fixture_function, request.instance)
309312
event_loop_fixture_id = _get_event_loop_fixture_id_for_async_fixture(
310313
request, func
311314
)

0 commit comments

Comments
 (0)