File tree 2 files changed +31
-3
lines changed 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -595,9 +595,10 @@ def _get_active_fixturedef(
595
595
raise FixtureLookupError (argname , self )
596
596
fixturedef = fixturedefs [index ]
597
597
598
- if not inspect .iscoroutinefunction (
599
- self .function
600
- ) and inspect .iscoroutinefunction (fixturedef .func ):
598
+ if not inspect .iscoroutinefunction (self .function ) and (
599
+ inspect .iscoroutinefunction (fixturedef .func )
600
+ or inspect .isasyncgenfunction (fixturedef .func )
601
+ ):
601
602
if fixturedef ._autouse :
602
603
warnings .warn (
603
604
PytestRemovedIn9Warning (
Original file line number Diff line number Diff line change @@ -1313,6 +1313,33 @@ def test_foo(async_fixture):
1313
1313
result .assert_outcomes (errors = 1 )
1314
1314
1315
1315
1316
+ def test_error_on_sync_test_async_fixture_gen (pytester : Pytester ) -> None :
1317
+ pytester .makepyfile (
1318
+ test_sync = """
1319
+ import pytest
1320
+
1321
+ @pytest.fixture
1322
+ async def async_fixture():
1323
+ yield
1324
+
1325
+ def test_foo(async_fixture):
1326
+ ...
1327
+ """
1328
+ )
1329
+ result = pytester .runpytest ()
1330
+ result .stdout .fnmatch_lines (
1331
+ [
1332
+ (
1333
+ "*ERROR: Sync test requested async fixture. "
1334
+ "You may want to make the test asynchronous and run it with "
1335
+ "a suitable async framework test plugin.*"
1336
+ ),
1337
+ "*ERROR test_sync.py::test_foo*" ,
1338
+ ]
1339
+ )
1340
+ result .assert_outcomes (errors = 1 )
1341
+
1342
+
1316
1343
def test_warning_on_sync_test_async_autouse_fixture (pytester : Pytester ) -> None :
1317
1344
pytester .makepyfile (
1318
1345
test_sync = """
You can’t perform that action at this time.
0 commit comments