From 32977c44a2b4ed826c1fc8ebc0e7248d929faaa3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 10 Aug 2026 20:24:48 +0200 Subject: [PATCH] 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 --- Lib/test/test_subprocess.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index b9d15764c451ab..89e0422efb3697 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -2051,8 +2051,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":2: EncodingWarning: ")