Skip to content

Commit 8e100ea

Browse files
committed
fix tests
1 parent 5c41d50 commit 8e100ea

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/_pytest/fixtures.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,16 @@ def _get_active_fixturedef(
595595
raise FixtureLookupError(argname, self)
596596
fixturedef = fixturedefs[index]
597597

598-
if not inspect.iscoroutinefunction(self.function) and (
599-
inspect.iscoroutinefunction(fixturedef.func)
600-
or inspect.isasyncgenfunction(fixturedef.func)
598+
# Check for attempted use of an async fixture by a sync test
599+
# `self.scope` here is not the scope of the requested fixture, but the scope of
600+
# 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+
)
601608
):
602609
if fixturedef._autouse:
603610
warnings.warn(

0 commit comments

Comments
 (0)