File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,9 @@ def pytest_configure(config):
152152@hookimpl (trylast = True )
153153def pytest_pyfunc_call (pyfuncitem ):
154154 testfunction = pyfuncitem .obj
155- if iscoroutinefunction (testfunction ):
155+ if iscoroutinefunction (testfunction ) or (
156+ sys .version_info >= (3 , 6 ) and inspect .isasyncgenfunction (testfunction )
157+ ):
156158 msg = "async def functions are not natively supported and have been skipped.\n "
157159 msg += "You need to install a suitable plugin for your async framework, for example:\n "
158160 msg += " - pytest-asyncio\n "
Original file line number Diff line number Diff line change @@ -1207,3 +1207,31 @@ async def test_2():
12071207 assert (
12081208 result .stdout .str ().count ("async def functions are not natively supported" ) == 1
12091209 )
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+ "*async def 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 ("async def functions are not natively supported" ) == 1
1237+ )
You can’t perform that action at this time.
0 commit comments