We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c41d50 commit 8e100eaCopy full SHA for 8e100ea
src/_pytest/fixtures.py
@@ -595,9 +595,16 @@ def _get_active_fixturedef(
595
raise FixtureLookupError(argname, self)
596
fixturedef = fixturedefs[index]
597
598
- if not inspect.iscoroutinefunction(self.function) and (
599
- inspect.iscoroutinefunction(fixturedef.func)
600
- or inspect.isasyncgenfunction(fixturedef.func)
+ # Check for attempted use of an async fixture by a sync test
+ # `self.scope` here is not the scope of the requested fixture, but the scope of
+ # the requester.
601
+ if (
602
+ self.scope == "function"
603
+ and not inspect.iscoroutinefunction(self._pyfuncitem.obj)
604
+ and (
605
+ inspect.iscoroutinefunction(fixturedef.func)
606
+ or inspect.isasyncgenfunction(fixturedef.func)
607
+ )
608
):
609
if fixturedef._autouse:
610
warnings.warn(
0 commit comments