Skip to content

Commit 626d44b

Browse files
committed
refactor: _wrap_async_fixture receives the Fixture function rather than the FixtureDef.
1 parent 06ef78e commit 626d44b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pytest_asyncio/plugin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Iterator,
2222
Sequence,
2323
)
24+
from types import CoroutineType
2425
from typing import (
2526
Any,
2627
Callable,
@@ -268,7 +269,7 @@ def _synchronize_async_fixture(fixturedef: FixtureDef) -> None:
268269
if inspect.isasyncgenfunction(fixturedef.func):
269270
fixturedef.func = _wrap_asyncgen_fixture(fixturedef) # type: ignore[misc]
270271
elif inspect.iscoroutinefunction(fixturedef.func):
271-
fixturedef.func = _wrap_async_fixture(fixturedef) # type: ignore[misc]
272+
fixturedef.func = _wrap_async_fixture(fixturedef.func) # type: ignore[misc]
272273

273274

274275
def _add_kwargs(
@@ -346,10 +347,14 @@ async def async_finalizer() -> None:
346347
return _asyncgen_fixture_wrapper
347348

348349

349-
def _wrap_async_fixture(fixturedef: FixtureDef) -> Callable:
350-
fixture_function = fixturedef.func
350+
AsyncFixtureReturnType = TypeVar("AsyncFixtureReturnType")
351351

352-
@functools.wraps(fixture_function)
352+
353+
def _wrap_async_fixture(
354+
fixture_function: Callable[..., CoroutineType[Any, Any, AsyncFixtureReturnType]],
355+
) -> Callable[..., AsyncFixtureReturnType]:
356+
357+
@functools.wraps(fixture_function) # type: ignore[arg-type]
353358
def _async_fixture_wrapper(request: FixtureRequest, **kwargs: Any):
354359
func = _perhaps_rebind_fixture_func(fixture_function, request.instance)
355360
event_loop_fixture_id = _get_event_loop_fixture_id_for_async_fixture(

0 commit comments

Comments
 (0)