https://github.com/python/cpython/commit/b3144d91448f3b4e36f36d73046839aaf40a46d4
commit: b3144d91448f3b4e36f36d73046839aaf40a46d4
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-07-11T22:26:16Z
summary:

[3.15] gh-152132: Close stderr_copy in test_api.test_run (GH-153591) (#153595)

gh-152132: Close stderr_copy in test_api.test_run (GH-153591)

Previously, the test was leaking a file descriptor.
(cherry picked from commit 0023d5b23df09f18425fea9b9c54a37ba050d5cf)

Co-authored-by: Victor Stinner <[email protected]>

files:
M Lib/test/test_capi/test_run.py

diff --git a/Lib/test/test_capi/test_run.py b/Lib/test/test_capi/test_run.py
index 14f9833f63a4fb..7796c589b557c7 100644
--- a/Lib/test/test_capi/test_run.py
+++ b/Lib/test/test_capi/test_run.py
@@ -310,13 +310,15 @@ def check_run_interactive(self, run, encode_filename, 
use_loop=False):
             # supported". In this case, run the test without redirecting
             # stderr to a temporary file.
             self._check_run_interactive(run, encode_filename, use_loop)
-        else:
-            with tempfile.TemporaryFile() as tmp:
-                try:
-                    os.dup2(tmp.fileno(), STDERR_FD)
-                    self._check_run_interactive(run, encode_filename, use_loop)
-                finally:
-                    os.dup2(stderr_copy, STDERR_FD)
+            return
+
+        with tempfile.TemporaryFile() as tmp:
+            try:
+                os.dup2(tmp.fileno(), STDERR_FD)
+                self._check_run_interactive(run, encode_filename, use_loop)
+            finally:
+                os.dup2(stderr_copy, STDERR_FD)
+                os.close(stderr_copy)
 
     def test_run_interactiveone(self):
         # Test PyRun_InteractiveOne()

_______________________________________________
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