From 404894a84ac95c8c40220957f68e6fed6bd6fd45 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google]" Date: Tue, 19 Apr 2022 04:18:42 +0000 Subject: [PATCH 1/2] unittest.IsolatedAsyncioTestCase no longer leaks its executor. 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. --- Lib/unittest/async_case.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py index 23231199f98706..d9c694e368255d 100644 --- a/Lib/unittest/async_case.py +++ b/Lib/unittest/async_case.py @@ -148,6 +148,8 @@ def _tearDownAsyncioLoop(self): # 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() From 522e6e4c2e8b38331fed9c9a7a069e31ba950ada Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google]" Date: Tue, 19 Apr 2022 04:33:42 +0000 Subject: [PATCH 2/2] News entry. --- .../Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst 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 index 00000000000000..dfbaef4440e0a6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst @@ -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.