|
21 | 21 | Iterator, |
22 | 22 | Sequence, |
23 | 23 | ) |
24 | | -from types import CoroutineType |
| 24 | +from types import AsyncGeneratorType, CoroutineType |
25 | 25 | from typing import ( |
26 | 26 | Any, |
27 | 27 | Callable, |
@@ -267,7 +267,7 @@ def _preprocess_async_fixtures( |
267 | 267 | def _synchronize_async_fixture(fixturedef: FixtureDef) -> None: |
268 | 268 | """Wraps the fixture function of an async fixture in a synchronous function.""" |
269 | 269 | 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] |
271 | 271 | elif inspect.iscoroutinefunction(fixturedef.func): |
272 | 272 | fixturedef.func = _wrap_async_fixture(fixturedef.func) # type: ignore[misc] |
273 | 273 |
|
@@ -300,12 +300,15 @@ def _perhaps_rebind_fixture_func(func: _T, instance: Any | None) -> _T: |
300 | 300 | return func |
301 | 301 |
|
302 | 302 |
|
303 | | -def _wrap_asyncgen_fixture(fixturedef: FixtureDef) -> Callable: |
304 | | - fixture = fixturedef.func |
| 303 | +AsyncGenFixtureYieldType = TypeVar("AsyncGenFixtureYieldType") |
305 | 304 |
|
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) |
307 | 310 | 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) |
309 | 312 | event_loop_fixture_id = _get_event_loop_fixture_id_for_async_fixture( |
310 | 313 | request, func |
311 | 314 | ) |
|
0 commit comments