https://github.com/python/cpython/commit/f81c03a673ae1c71ad18845b0407f26e6cf64159
commit: f81c03a673ae1c71ad18845b0407f26e6cf64159
branch: main
author: Eugene Amirov <[email protected]>
committer: ncoghlan <[email protected]>
date: 2026-08-30T12:10:38+10:00
summary:

gh-142414: Isolate reloading modules in test_interpreters (#144096)

Isolate reloading modules in test_interpreters

Co-authored-by: Alyssa Coghlan <[email protected]>

files:
A Misc/NEWS.d/next/Tests/2026-01-21-02-03-31.gh-issue-142414.CfcgiR.rst
M Lib/test/test_interpreters/test_channels.py
M Lib/test/test_interpreters/test_queues.py

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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to