|
23 | 23 | from _pytest.compat import getimfunc
|
24 | 24 | from _pytest.compat import getlocation
|
25 | 25 | from _pytest.compat import is_generator
|
| 26 | +from _pytest.compat import iscoroutinefunction |
26 | 27 | from _pytest.compat import NOTSET
|
27 | 28 | from _pytest.compat import REGEX_TYPE
|
28 | 29 | from _pytest.compat import safe_getattr
|
@@ -151,15 +152,16 @@ def pytest_configure(config):
|
151 | 152 | @hookimpl(trylast=True)
|
152 | 153 | def pytest_pyfunc_call(pyfuncitem):
|
153 | 154 | testfunction = pyfuncitem.obj
|
154 |
| - iscoroutinefunction = getattr(inspect, "iscoroutinefunction", None) |
155 |
| - if iscoroutinefunction is not None and iscoroutinefunction(testfunction): |
156 |
| - msg = "Coroutine functions are not natively supported and have been skipped.\n" |
| 155 | + if iscoroutinefunction(testfunction) or ( |
| 156 | + sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction) |
| 157 | + ): |
| 158 | + msg = "async def functions are not natively supported and have been skipped.\n" |
157 | 159 | msg += "You need to install a suitable plugin for your async framework, for example:\n"
|
158 | 160 | msg += " - pytest-asyncio\n"
|
159 | 161 | msg += " - pytest-trio\n"
|
160 | 162 | msg += " - pytest-tornasync"
|
161 | 163 | warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid)))
|
162 |
| - skip(msg="coroutine function and no async plugin installed (see warnings)") |
| 164 | + skip(msg="async def function and no async plugin installed (see warnings)") |
163 | 165 | funcargs = pyfuncitem.funcargs
|
164 | 166 | testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
|
165 | 167 | testfunction(**testargs)
|
|
0 commit comments