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 pytest_pyfunc_call(pyfuncitem):
|
||||
def async_warn():
|
||||
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 += " - pytest-asyncio\n"
|
||||
msg += " - pytest-trio\n"
|
||||
msg += " - pytest-tornasync"
|
||||
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid)))
|
||||
skip(msg="async def function and no async plugin installed (see warnings)")
|
||||
def async_warn(nodeid: str) -> None:
|
||||
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 += " - pytest-asyncio\n"
|
||||
msg += " - pytest-trio\n"
|
||||
msg += " - pytest-tornasync"
|
||||
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
|
||||
skip(msg="async def function and no async plugin installed (see warnings)")
|
||||
|
||||
|
||||
@hookimpl(trylast=True)
|
||||
def pytest_pyfunc_call(pyfuncitem: "Function"):
|
||||
testfunction = pyfuncitem.obj
|
||||
if iscoroutinefunction(testfunction) or (
|
||||
sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction)
|
||||
):
|
||||
async_warn()
|
||||
async_warn(pyfuncitem.nodeid)
|
||||
funcargs = pyfuncitem.funcargs
|
||||
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
|
||||
result = testfunction(**testargs)
|
||||
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
|
||||
async_warn()
|
||||
async_warn(pyfuncitem.nodeid)
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue