Skip to content

Commit 442dcce

Browse files
committed
python: factor out async_warn
1 parent eb5e651 commit 442dcce

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/_pytest/python.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,30 @@ def pytest_configure(config):
146146
)
147147

148148

149-
@hookimpl(trylast=True)
150-
def pytest_pyfunc_call(pyfuncitem):
151-
def async_warn():
152-
msg = "async def functions are not natively supported and have been skipped.\n"
153-
msg += "You need to install a suitable plugin for your async framework, for example:\n"
154-
msg += " - pytest-asyncio\n"
155-
msg += " - pytest-trio\n"
156-
msg += " - pytest-tornasync"
157-
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid)))
158-
skip(msg="async def function and no async plugin installed (see warnings)")
149+
def async_warn(nodeid: str) -> None:
150+
msg = "async def functions are not natively supported and have been skipped.\n"
151+
msg += (
152+
"You need to install a suitable plugin for your async framework, for example:\n"
153+
)
154+
msg += " - pytest-asyncio\n"
155+
msg += " - pytest-trio\n"
156+
msg += " - pytest-tornasync"
157+
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
158+
skip(msg="async def function and no async plugin installed (see warnings)")
159159

160+
161+
@hookimpl(trylast=True)
162+
def pytest_pyfunc_call(pyfuncitem: "Function"):
160163
testfunction = pyfuncitem.obj
161164
if iscoroutinefunction(testfunction) or (
162165
sys.version_info >= (3, 6) and inspect.isasyncgenfunction(testfunction)
163166
):
164-
async_warn()
167+
async_warn(pyfuncitem.nodeid)
165168
funcargs = pyfuncitem.funcargs
166169
testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
167170
result = testfunction(**testargs)
168171
if hasattr(result, "__await__") or hasattr(result, "__aiter__"):
169-
async_warn()
172+
async_warn(pyfuncitem.nodeid)
170173
return True
171174

172175

0 commit comments

Comments
 (0)