]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks its executo...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 19 Apr 2022 16:40:52 +0000 (09:40 -0700)
committerGitHub <noreply@github.com>
Tue, 19 Apr 2022 16:40:52 +0000 (09:40 -0700)
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 61570ae0bc1507a62bee9d8b9bc2ff7155da7061)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Lib/unittest/async_case.py
Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst [new file with mode: 0644]

index 23231199f9870604fd7a33882b51ec2c829545a3..d9c694e368255dec153a01323eee13e2510deb1b 100644 (file)
@@ -148,6 +148,8 @@ class IsolatedAsyncioTestCase(TestCase):
             # shutdown asyncgens
             loop.run_until_complete(loop.shutdown_asyncgens())
         finally:
+            # Prevent our executor environment from leaking to future tests.
+            loop.run_until_complete(loop.shutdown_default_executor())
             asyncio.set_event_loop(None)
             loop.close()
 
diff --git a/Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst b/Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst
new file mode 100644 (file)
index 0000000..dfbaef4
--- /dev/null
@@ -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.