34
34
from _pytest .compat import get_real_func
35
35
from _pytest .compat import getimfunc
36
36
from _pytest .compat import getlocation
37
+ from _pytest .compat import is_async_function
37
38
from _pytest .compat import is_generator
38
- from _pytest .compat import iscoroutinefunction
39
39
from _pytest .compat import NOTSET
40
40
from _pytest .compat import REGEX_TYPE
41
41
from _pytest .compat import safe_getattr
@@ -159,7 +159,7 @@ def pytest_configure(config):
159
159
)
160
160
161
161
162
- def async_warn (nodeid : str ) -> None :
162
+ def async_warn_and_skip (nodeid : str ) -> None :
163
163
msg = "async def functions are not natively supported and have been skipped.\n "
164
164
msg += (
165
165
"You need to install a suitable plugin for your async framework, for example:\n "
@@ -175,33 +175,13 @@ def async_warn(nodeid: str) -> None:
175
175
@hookimpl (trylast = True )
176
176
def pytest_pyfunc_call (pyfuncitem : "Function" ):
177
177
testfunction = pyfuncitem .obj
178
-
179
- try :
180
- # ignoring type as the import is invalid in py37 and mypy thinks its a error
181
- from unittest import IsolatedAsyncioTestCase # type: ignore
182
- except ImportError :
183
- async_ok_in_stdlib = False
184
- else :
185
- async_ok_in_stdlib = isinstance (
186
- getattr (testfunction , "__self__" , None ), IsolatedAsyncioTestCase
187
- )
188
-
189
- if (
190
- iscoroutinefunction (testfunction )
191
- or (sys .version_info >= (3 , 6 ) and inspect .isasyncgenfunction (testfunction ))
192
- ) and not async_ok_in_stdlib :
193
- async_warn (pyfuncitem .nodeid )
178
+ if is_async_function (testfunction ):
179
+ async_warn_and_skip (pyfuncitem .nodeid )
194
180
funcargs = pyfuncitem .funcargs
195
181
testargs = {arg : funcargs [arg ] for arg in pyfuncitem ._fixtureinfo .argnames }
196
182
result = testfunction (** testargs )
197
183
if hasattr (result , "__await__" ) or hasattr (result , "__aiter__" ):
198
- if async_ok_in_stdlib :
199
- # todo: investigate moving this to the unittest plugin
200
- # by a test call result hook
201
- testcase = testfunction .__self__
202
- testcase ._callMaybeAsync (lambda : result )
203
- else :
204
- async_warn (pyfuncitem .nodeid )
184
+ async_warn_and_skip (pyfuncitem .nodeid )
205
185
return True
206
186
207
187
0 commit comments