Skip to content

Commit b2aadb8

Browse files
shoehorn unittest async results into python test result interpretation
1 parent c5e060a commit b2aadb8

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
@@ -194,10 +194,14 @@ def pytest_pyfunc_call(pyfuncitem: "Function"):
194194
funcargs = pyfuncitem.funcargs
195195
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
196196
result = testfunction(**testargs)
197-
if (
198-
hasattr(result, "__await__") or hasattr(result, "__aiter__")
199-
) and not async_ok_in_stdlib:
200-
async_warn(pyfuncitem.nodeid)
197+
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)
201205
return True
202206

203207

0 commit comments

Comments
 (0)