File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed
Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -151,20 +151,25 @@ def pytest_configure(config):
151151
152152@hookimpl (trylast = True )
153153def pytest_pyfunc_call (pyfuncitem ):
154- testfunction = pyfuncitem .obj
155- if iscoroutinefunction (testfunction ) or (
156- sys .version_info >= (3 , 6 ) and inspect .isasyncgenfunction (testfunction )
157- ):
154+ def async_warn ():
158155 msg = "async def functions are not natively supported and have been skipped.\n "
159156 msg += "You need to install a suitable plugin for your async framework, for example:\n "
160157 msg += " - pytest-asyncio\n "
161158 msg += " - pytest-trio\n "
162159 msg += " - pytest-tornasync"
163160 warnings .warn (PytestUnhandledCoroutineWarning (msg .format (pyfuncitem .nodeid )))
164161 skip (msg = "async def function and no async plugin installed (see warnings)" )
162+
163+ testfunction = pyfuncitem .obj
164+ if iscoroutinefunction (testfunction ) or (
165+ sys .version_info >= (3 , 6 ) and inspect .isasyncgenfunction (testfunction )
166+ ):
167+ async_warn ()
165168 funcargs = pyfuncitem .funcargs
166169 testargs = {arg : funcargs [arg ] for arg in pyfuncitem ._fixtureinfo .argnames }
167- testfunction (** testargs )
170+ result = testfunction (** testargs )
171+ if hasattr (result , "__await__" ) or hasattr (result , "__aiter__" ):
172+ async_warn ()
168173 return True
169174
170175
Original file line number Diff line number Diff line change @@ -1192,15 +1192,18 @@ async def test_1():
11921192 pass
11931193 async def test_2():
11941194 pass
1195+ def test_3():
1196+ return test_2()
11951197 """
11961198 )
11971199 result = testdir .runpytest ()
11981200 result .stdout .fnmatch_lines (
11991201 [
12001202 "test_async.py::test_1" ,
12011203 "test_async.py::test_2" ,
1204+ "test_async.py::test_3" ,
12021205 "*async def functions are not natively supported*" ,
1203- "*2 skipped, 2 warnings in*" ,
1206+ "*3 skipped, 3 warnings in*" ,
12041207 ]
12051208 )
12061209 # ensure our warning message appears only once
@@ -1220,15 +1223,18 @@ async def test_1():
12201223 yield
12211224 async def test_2():
12221225 yield
1226+ def test_3():
1227+ return test_2()
12231228 """
12241229 )
12251230 result = testdir .runpytest ()
12261231 result .stdout .fnmatch_lines (
12271232 [
12281233 "test_async.py::test_1" ,
12291234 "test_async.py::test_2" ,
1235+ "test_async.py::test_3" ,
12301236 "*async def functions are not natively supported*" ,
1231- "*2 skipped, 2 warnings in*" ,
1237+ "*3 skipped, 3 warnings in*" ,
12321238 ]
12331239 )
12341240 # ensure our warning message appears only once
You can’t perform that action at this time.
0 commit comments