(pytester: Pytester)
| 1152 | |
| 1153 | @pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning") |
| 1154 | def 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") |
nothing calls this directly
no test coverage detected