Skip to content

Commit 8bc0e19

Browse files
committed
test error handling for shutdown_asyncgens
turns failure to cleanup errors into warnings
1 parent 569b29c commit 8bc0e19

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_event_loop_fixture.py

+26
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,29 @@ async def test_something(cleanup_after):
112112
)
113113
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
114114
result.assert_outcomes(passed=1, warnings=0)
115+
116+
117+
def test_event_loop_fixture_asyncgen_error(
118+
pytester: Pytester,
119+
):
120+
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
121+
pytester.makepyfile(
122+
dedent(
123+
"""\
124+
import asyncio
125+
import pytest
126+
127+
pytest_plugins = 'pytest_asyncio'
128+
129+
@pytest.mark.asyncio
130+
async def test_something():
131+
# mock shutdown_asyncgen failure
132+
loop = asyncio.get_running_loop()
133+
async def fail():
134+
raise RuntimeError("mock error cleaning up...")
135+
loop.shutdown_asyncgens = fail
136+
"""
137+
)
138+
)
139+
result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
140+
result.assert_outcomes(passed=1, warnings=1)

0 commit comments

Comments
 (0)