File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,10 @@ def pytest_configure(config):
152
152
def pytest_pyfunc_call (pyfuncitem ):
153
153
testfunction = pyfuncitem .obj
154
154
iscoroutinefunction = getattr (inspect , "iscoroutinefunction" , None )
155
- if iscoroutinefunction is not None and iscoroutinefunction (testfunction ):
155
+ isasyncgenfunction = getattr (inspect , "isasyncgenfunction" , None )
156
+ if (iscoroutinefunction is not None and iscoroutinefunction (testfunction )) or (
157
+ isasyncgenfunction is not None and isasyncgenfunction (testfunction )
158
+ ):
156
159
msg = "Coroutine functions are not natively supported and have been skipped.\n "
157
160
msg += "You need to install a suitable plugin for your async framework, for example:\n "
158
161
msg += " - pytest-asyncio\n "
Original file line number Diff line number Diff line change @@ -1207,3 +1207,31 @@ async def test_2():
1207
1207
assert (
1208
1208
result .stdout .str ().count ("Coroutine functions are not natively supported" ) == 1
1209
1209
)
1210
+
1211
+
1212
+ @pytest .mark .filterwarnings ("default" )
1213
+ @pytest .mark .skipif (
1214
+ sys .version_info < (3 , 6 ), reason = "async gen syntax available in Python 3.6+"
1215
+ )
1216
+ def test_warn_on_async_gen_function (testdir ):
1217
+ testdir .makepyfile (
1218
+ test_async = """
1219
+ async def test_1():
1220
+ yield
1221
+ async def test_2():
1222
+ yield
1223
+ """
1224
+ )
1225
+ result = testdir .runpytest ()
1226
+ result .stdout .fnmatch_lines (
1227
+ [
1228
+ "test_async.py::test_1" ,
1229
+ "test_async.py::test_2" ,
1230
+ "*Coroutine functions are not natively supported*" ,
1231
+ "*2 skipped, 2 warnings in*" ,
1232
+ ]
1233
+ )
1234
+ # ensure our warning message appears only once
1235
+ assert (
1236
+ result .stdout .str ().count ("Coroutine functions are not natively supported" ) == 1
1237
+ )
You can’t perform that action at this time.
0 commit comments