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):
151
151
152
152
@hookimpl (trylast = True )
153
153
def 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 ():
158
155
msg = "async def functions are not natively supported and have been skipped.\n "
159
156
msg += "You need to install a suitable plugin for your async framework, for example:\n "
160
157
msg += " - pytest-asyncio\n "
161
158
msg += " - pytest-trio\n "
162
159
msg += " - pytest-tornasync"
163
160
warnings .warn (PytestUnhandledCoroutineWarning (msg .format (pyfuncitem .nodeid )))
164
161
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 ()
165
168
funcargs = pyfuncitem .funcargs
166
169
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 ()
168
173
return True
169
174
170
175
Original file line number Diff line number Diff line change @@ -1192,15 +1192,18 @@ async def test_1():
1192
1192
pass
1193
1193
async def test_2():
1194
1194
pass
1195
+ def test_3():
1196
+ return test_2()
1195
1197
"""
1196
1198
)
1197
1199
result = testdir .runpytest ()
1198
1200
result .stdout .fnmatch_lines (
1199
1201
[
1200
1202
"test_async.py::test_1" ,
1201
1203
"test_async.py::test_2" ,
1204
+ "test_async.py::test_3" ,
1202
1205
"*async def functions are not natively supported*" ,
1203
- "*2 skipped, 2 warnings in*" ,
1206
+ "*3 skipped, 3 warnings in*" ,
1204
1207
]
1205
1208
)
1206
1209
# ensure our warning message appears only once
@@ -1220,15 +1223,18 @@ async def test_1():
1220
1223
yield
1221
1224
async def test_2():
1222
1225
yield
1226
+ def test_3():
1227
+ return test_2()
1223
1228
"""
1224
1229
)
1225
1230
result = testdir .runpytest ()
1226
1231
result .stdout .fnmatch_lines (
1227
1232
[
1228
1233
"test_async.py::test_1" ,
1229
1234
"test_async.py::test_2" ,
1235
+ "test_async.py::test_3" ,
1230
1236
"*async def functions are not natively supported*" ,
1231
- "*2 skipped, 2 warnings in*" ,
1237
+ "*3 skipped, 3 warnings in*" ,
1232
1238
]
1233
1239
)
1234
1240
# ensure our warning message appears only once
You can’t perform that action at this time.
0 commit comments