MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_warn_on_async_function

Function test_warn_on_async_function

testing/acceptance_test.py:1154–1183  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

1152
1153@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
1154def test_warn_on_async_function(pytester: Pytester) -> None:
1155 # In the below we .close() the coroutine only to avoid
1156 # "RuntimeWarning: coroutine 'test_2' was never awaited"
1157 # which messes with other tests.
1158 pytester.makepyfile(
1159 test_async="""
1160 async def test_1():
1161 pass
1162 async def test_2():
1163 pass
1164 def test_3():
1165 coro = test_2()
1166 coro.close()
1167 return coro
1168 """
1169 )
1170 result = pytester.runpytest()
1171 result.stdout.fnmatch_lines(
1172 [
1173 "test_async.py::test_1",
1174 "test_async.py::test_2",
1175 "test_async.py::test_3",
1176 "*async def functions are not natively supported*",
1177 "*3 skipped, 3 warnings in*",
1178 ]
1179 )
1180 # ensure our warning message appears only once
1181 assert (
1182 result.stdout.str().count("async def functions are not natively supported") == 1
1183 )
1184
1185
1186@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
countMethod · 0.80
strMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected