[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 61570ae0bc)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Miss Islington (bot) 2022-04-19 09:40:52 -07:00 committed by GitHub
parent 3b6072e7f5
commit cb3c85d40d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -148,6 +148,8 @@ def _tearDownAsyncioLoop(self):
# shutdown asyncgens # shutdown asyncgens
loop.run_until_complete(loop.shutdown_asyncgens()) loop.run_until_complete(loop.shutdown_asyncgens())
finally: finally:
# Prevent our executor environment from leaking to future tests.
loop.run_until_complete(loop.shutdown_default_executor())
asyncio.set_event_loop(None) asyncio.set_event_loop(None)
loop.close() loop.close()

View file

@ -0,0 +1,4 @@
Fix :class:`unittest.IsolatedAsyncioTestCase` to shutdown the per test event
loop executor before returning from its ``run`` method so that a not yet
stopped or garbage collected executor state does not persist beyond the
test.