Skip to content

Commit dbe0009

Browse files
committed
Resolve fixture early
1 parent fb9fe7e commit dbe0009

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pytest_asyncio/plugin.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,14 @@ def _can_substitute(item: Function) -> bool:
540540

541541
def setup(self) -> None:
542542
runner_fixture_id = f"_{self._loop_scope}_scoped_runner"
543-
if runner_fixture_id in self.fixturenames:
544-
return super().setup()
545-
# The runner must be resolved before async fixtures when loop
546-
# factories are configured. Otherwise, the async fixtures see a
547-
# stale loop from the previous factory.
543+
if runner_fixture_id not in self.fixturenames:
544+
self.fixturenames.append(runner_fixture_id)
545+
# When loop factories are configured, resolve the loop factory
546+
# fixture early so that a factory variant change cascades cache
547+
# invalidation before any async fixture checks its cache.
548548
hook_caller = self.config.hook.pytest_asyncio_loop_factories
549549
if hook_caller.get_hookimpls():
550-
self.fixturenames.insert(0, runner_fixture_id)
551-
else:
552-
self.fixturenames.append(runner_fixture_id)
550+
_ = self._request.getfixturevalue(_asyncio_loop_factory.__name__)
553551
return super().setup()
554552

555553
def runtest(self) -> None:

0 commit comments

Comments
 (0)