[3.13] gh-155491: Fix subprocess test_encoding_warning() (GH-155492) (#155508)

vstinner <[email protected]> Mon, 10 Aug 2026 14:46:12 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/178aaa211c872b7264e7db0e42bf92dc626f10d8
commit: 178aaa211c872b7264e7db0e42bf92dc626f10d8
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-08-10T18:44:15Z
summary:

[3.13] gh-155491: Fix subprocess test_encoding_warning() (GH-155492) (#155508)

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 6b541da52310a3..9b14c376a4f8c1 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -2015,8 +2015,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.assertTrue(lines[0].startswith(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]