Skip to content

Commit cb3c85d

Browse files
[3.10] gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks its executor (GH-91680)
For things like test_asyncio.test_thread this was causing frequent "environment modified by test" errors as the executor threads had not always stopped running after the test was over. (cherry picked from commit 61570ae) Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent 3b6072e commit cb3c85d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Lib/unittest/async_case.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def _tearDownAsyncioLoop(self):
148148
# shutdown asyncgens
149149
loop.run_until_complete(loop.shutdown_asyncgens())
150150
finally:
151+
# Prevent our executor environment from leaking to future tests.
152+
loop.run_until_complete(loop.shutdown_default_executor())
151153
asyncio.set_event_loop(None)
152154
loop.close()
153155

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix :class:`unittest.IsolatedAsyncioTestCase` to shutdown the per test event
2+
loop executor before returning from its ``run`` method so that a not yet
3+
stopped or garbage collected executor state does not persist beyond the
4+
test.

0 commit comments

Comments
 (0)