Skip to content

Commit 8432333

Browse files
committed
refactor: _synchronize_fixture returns a callable rather than modifying the fixture.
1 parent 395c738 commit 8432333

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pytest_asyncio/plugin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,19 @@ def _preprocess_async_fixtures(
259259
_make_asyncio_fixture_function(func, loop_scope)
260260
if "request" not in fixturedef.argnames:
261261
fixturedef.argnames += ("request",)
262-
_synchronize_async_fixture(fixturedef)
262+
fixturedef.func = _fixture_synchronizer(fixturedef) # type: ignore[misc]
263263
assert _is_asyncio_fixture_function(fixturedef.func)
264264
processed_fixturedefs.add(fixturedef)
265265

266266

267-
def _synchronize_async_fixture(fixturedef: FixtureDef) -> None:
268-
"""Wraps the fixture function of an async fixture in a synchronous function."""
267+
def _fixture_synchronizer(fixturedef: FixtureDef) -> Callable:
268+
"""Returns a synchronous function evaluating the specified fixture."""
269269
if inspect.isasyncgenfunction(fixturedef.func):
270-
fixturedef.func = _wrap_asyncgen_fixture(fixturedef.func) # type: ignore[misc]
270+
return _wrap_asyncgen_fixture(fixturedef.func)
271271
elif inspect.iscoroutinefunction(fixturedef.func):
272-
fixturedef.func = _wrap_async_fixture(fixturedef.func) # type: ignore[misc]
272+
return _wrap_async_fixture(fixturedef.func)
273+
else:
274+
return fixturedef.func
273275

274276

275277
def _add_kwargs(

0 commit comments

Comments
 (0)