commit
2d613a03b3
|
@ -151,10 +151,7 @@ def pytest_configure(config):
|
||||||
|
|
||||||
@hookimpl(trylast=True)
|
@hookimpl(trylast=True)
|
||||||
def pytest_pyfunc_call(pyfuncitem):
|
def pytest_pyfunc_call(pyfuncitem):
|
||||||
testfunction = pyfuncitem.obj
|
def async_warn():
|
||||||
if iscoroutinefunction(testfunction) or (
|
|
||||||
sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction)
|
|
||||||
):
|
|
||||||
msg = "async def functions are not natively supported and have been skipped.\n"
|
msg = "async def functions are not natively supported and have been skipped.\n"
|
||||||
msg += "You need to install a suitable plugin for your async framework, for example:\n"
|
msg += "You need to install a suitable plugin for your async framework, for example:\n"
|
||||||
msg += " - pytest-asyncio\n"
|
msg += " - pytest-asyncio\n"
|
||||||
|
@ -162,9 +159,17 @@ def pytest_pyfunc_call(pyfuncitem):
|
||||||
msg += " - pytest-tornasync"
|
msg += " - pytest-tornasync"
|
||||||
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid)))
|
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid)))
|
||||||
skip(msg="async def function and no async plugin installed (see warnings)")
|
skip(msg="async def function and no async plugin installed (see warnings)")
|
||||||
|
|
||||||
|
testfunction = pyfuncitem.obj
|
||||||
|
if iscoroutinefunction(testfunction) or (
|
||||||
|
sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction)
|
||||||
|
):
|
||||||
|
async_warn()
|
||||||
funcargs = pyfuncitem.funcargs
|
funcargs = pyfuncitem.funcargs
|
||||||
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
|
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
|
||||||
testfunction(**testargs)
|
result = testfunction(**testargs)
|
||||||
|
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
|
||||||
|
async_warn()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1192,6 +1192,8 @@ def test_warn_on_async_function(testdir):
|
||||||
pass
|
pass
|
||||||
async def test_2():
|
async def test_2():
|
||||||
pass
|
pass
|
||||||
|
def test_3():
|
||||||
|
return test_2()
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -1199,8 +1201,9 @@ def test_warn_on_async_function(testdir):
|
||||||
[
|
[
|
||||||
"test_async.py::test_1",
|
"test_async.py::test_1",
|
||||||
"test_async.py::test_2",
|
"test_async.py::test_2",
|
||||||
|
"test_async.py::test_3",
|
||||||
"*async def functions are not natively supported*",
|
"*async def functions are not natively supported*",
|
||||||
"*2 skipped, 2 warnings in*",
|
"*3 skipped, 3 warnings in*",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
# ensure our warning message appears only once
|
# ensure our warning message appears only once
|
||||||
|
@ -1220,6 +1223,8 @@ def test_warn_on_async_gen_function(testdir):
|
||||||
yield
|
yield
|
||||||
async def test_2():
|
async def test_2():
|
||||||
yield
|
yield
|
||||||
|
def test_3():
|
||||||
|
return test_2()
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
|
@ -1227,8 +1232,9 @@ def test_warn_on_async_gen_function(testdir):
|
||||||
[
|
[
|
||||||
"test_async.py::test_1",
|
"test_async.py::test_1",
|
||||||
"test_async.py::test_2",
|
"test_async.py::test_2",
|
||||||
|
"test_async.py::test_3",
|
||||||
"*async def functions are not natively supported*",
|
"*async def functions are not natively supported*",
|
||||||
"*2 skipped, 2 warnings in*",
|
"*3 skipped, 3 warnings in*",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
# ensure our warning message appears only once
|
# ensure our warning message appears only once
|
||||||
|
|
Loading…
Reference in New Issue