Merge pull request #6633 from blueyed/async_warn
python: factor out async_warn
This commit is contained in:
commit
1dc265e34a
|
@ -146,27 +146,30 @@ def pytest_configure(config):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@hookimpl(trylast=True)
|
def async_warn(nodeid: str) -> None:
|
||||||
def pytest_pyfunc_call(pyfuncitem):
|
msg = "async def functions are not natively supported and have been skipped.\n"
|
||||||
def async_warn():
|
msg += (
|
||||||
msg = "async def functions are not natively supported and have been skipped.\n"
|
"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"
|
||||||
msg += " - pytest-trio\n"
|
msg += " - pytest-trio\n"
|
||||||
msg += " - pytest-tornasync"
|
msg += " - pytest-tornasync"
|
||||||
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid)))
|
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(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)")
|
||||||
|
|
||||||
|
|
||||||
|
@hookimpl(trylast=True)
|
||||||
|
def pytest_pyfunc_call(pyfuncitem: "Function"):
|
||||||
testfunction = pyfuncitem.obj
|
testfunction = pyfuncitem.obj
|
||||||
if iscoroutinefunction(testfunction) or (
|
if iscoroutinefunction(testfunction) or (
|
||||||
sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction)
|
sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction)
|
||||||
):
|
):
|
||||||
async_warn()
|
async_warn(pyfuncitem.nodeid)
|
||||||
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}
|
||||||
result = testfunction(**testargs)
|
result = testfunction(**testargs)
|
||||||
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
|
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
|
||||||
async_warn()
|
async_warn(pyfuncitem.nodeid)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue