Skip to content

Commit 8bb51f4

Browse files
committed
Add test for verifying task cancellation
1 parent 338753b commit 8bb51f4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_event_loop_cleanup.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from textwrap import dedent
2+
3+
4+
def test_task_canceled_on_test_end(testdir):
5+
testdir.makepyfile(
6+
dedent(
7+
"""\
8+
import asyncio
9+
import pytest
10+
11+
pytest_plugins = 'pytest_asyncio'
12+
13+
@pytest.mark.asyncio
14+
async def test_a():
15+
loop = asyncio.get_event_loop()
16+
17+
async def run_forever():
18+
while True:
19+
await asyncio.sleep(0.1)
20+
21+
loop.create_task(run_forever())
22+
"""
23+
)
24+
)
25+
testdir.makefile(
26+
".ini",
27+
pytest=dedent(
28+
"""\
29+
[pytest]
30+
asyncio_mode = strict
31+
filterwarnings =
32+
error
33+
"""
34+
),
35+
)
36+
result = testdir.runpytest_subprocess()
37+
result.assert_outcomes(passed=1)
38+
result.stderr.no_fnmatch_line("Task was destroyed but it is pending!")

0 commit comments

Comments
 (0)