[3.14] gh-155491: Fix subprocess test_encoding_warning() (GH-155492) (#155507)

vstinner <[email protected]> Mon, 10 Aug 2026 14:57:35 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/4ee3c23cf5567417f27b30273323394770b4e95a
commit: 4ee3c23cf5567417f27b30273323394770b4e95a
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-08-10T18:51:16Z
summary:

[3.14] gh-155491: Fix subprocess test_encoding_warning() (GH-155492) (#155507)

gh-155491: Fix subprocess test_encoding_warning() (GH-155492)

The test fails if run using PYTHONWARNINGS=error environment
variable. Use make_clean_env() function to not inherit PYTHON
environment variables.
(cherry picked from commit 433c842b39a9b930b7e2d6aafeca722fd68a3323)

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

files:
M Lib/test/test_subprocess.py

diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 70e58c965ab955..d13f0ec2522abd 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -2016,8 +2016,9 @@ def test_encoding_warning(self):
             run("echo hello", shell=True, text=True)
             check_output("echo hello", shell=True, text=True)
             """)
+        env = support.make_clean_env()
         cp = subprocess.run([sys.executable, "-Xwarn_default_encoding", "-c", code],
-                            capture_output=True)
+                            capture_output=True, env=env)
         lines = cp.stderr.splitlines()
         self.assertEqual(len(lines), 2, lines)
         self.assertStartsWith(lines[0], b"<string>:2: EncodingWarning: ")

_______________________________________________
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]