From f81c03a673ae1c71ad18845b0407f26e6cf64159 Mon Sep 17 00:00:00 2001 From: Eugene Amirov <2597566+Allactaga@users.noreply.github.com> Date: Sun, 30 Aug 2026 04:10:38 +0200 Subject: [PATCH] gh-142414: Isolate reloading modules in test_interpreters (#144096) Isolate reloading modules in test_interpreters Co-authored-by: Alyssa Coghlan --- Lib/test/test_interpreters/test_channels.py | 8 ++++++-- Lib/test/test_interpreters/test_queues.py | 8 ++++++-- .../Tests/2026-01-21-02-03-31.gh-issue-142414.CfcgiR.rst | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2026-01-21-02-03-31.gh-issue-142414.CfcgiR.rst diff --git a/Lib/test/test_interpreters/test_channels.py b/Lib/test/test_interpreters/test_channels.py index 5437792b5a7014a..1adba40b740895f 100644 --- a/Lib/test/test_interpreters/test_channels.py +++ b/Lib/test/test_interpreters/test_channels.py @@ -1,4 +1,3 @@ -import importlib import pickle import threading from textwrap import dedent @@ -28,7 +27,12 @@ class LowLevelTests(TestBase): def test_highlevel_reloaded(self): # See gh-115490 (https://github.com/python/cpython/issues/115490). - importlib.reload(channels) + interp = interpreters.create() + interp.exec(dedent(f""" + import importlib + from test.support import channels + importlib.reload(channels) + """)); class TestChannels(TestBase): diff --git a/Lib/test/test_interpreters/test_queues.py b/Lib/test/test_interpreters/test_queues.py index baa772b3b367952..06d8e23b1fbca2f 100644 --- a/Lib/test/test_interpreters/test_queues.py +++ b/Lib/test/test_interpreters/test_queues.py @@ -1,4 +1,3 @@ -import importlib import pickle import threading from textwrap import dedent @@ -41,7 +40,12 @@ class LowLevelTests(TestBase): def test_highlevel_reloaded(self): # See gh-115490 (https://github.com/python/cpython/issues/115490). - importlib.reload(queues) + interp = interpreters.create() + interp.exec(dedent(f""" + import importlib + from concurrent.interpreters import _queues as queues + importlib.reload(queues) + """)); def test_create_destroy(self): qid = _queues.create(2, REPLACE, -1) diff --git a/Misc/NEWS.d/next/Tests/2026-01-21-02-03-31.gh-issue-142414.CfcgiR.rst b/Misc/NEWS.d/next/Tests/2026-01-21-02-03-31.gh-issue-142414.CfcgiR.rst new file mode 100644 index 000000000000000..6d4cbfc490a17db --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-01-21-02-03-31.gh-issue-142414.CfcgiR.rst @@ -0,0 +1,2 @@ +Isolate reloading modules in test_interpreters to avoid having broken +references.