Skip to content

Commit ec2cb0f

Browse files
shoehorn unittest async results into python test result interpretation
1 parent cfac682 commit ec2cb0f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/_pytest/python.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,14 @@ def pytest_pyfunc_call(pyfuncitem: "Function"):
192192
funcargs = pyfuncitem.funcargs
193193
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
194194
result = testfunction(**testargs)
195-
if (
196-
hasattr(result, "__await__") or hasattr(result, "__aiter__")
197-
) and not async_ok_in_stdlib:
198-
async_warn(pyfuncitem.nodeid)
195+
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
196+
if async_ok_in_stdlib:
197+
# todo: investigate moving this to the unittest plugin
198+
# by a test call result hook
199+
testcase = testfunction.__self__
200+
testcase._callMaybeAsync(lambda: result)
201+
else:
202+
async_warn(pyfuncitem.nodeid)
199203
return True
200204

201205

0 commit comments

Comments
 (0)