From 204b71af27fd1415c4908e8891911a52fce3749f Mon Sep 17 00:00:00 2001 From: Xia Jiang Date: Sun, 25 Oct 2026 21:37:40 +0800 Subject: [PATCH] gh-160652: Make test_getoutput independent of the console code page The shell writes its error message in the console code page, which is not necessarily the encoding text mode picks (UTF-8 once UTF-8 mode is on). Only the exit status is checked here, so tolerate undecodable bytes instead of failing on them. --- Lib/test/test_subprocess.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index dedd3cc0e9e867..e2add09244c974 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -4132,8 +4132,10 @@ def test_getoutput(self): try: dir = tempfile.mkdtemp() name = os.path.join(dir, "foo") + # The message comes from the shell in the console code page, + # which need not be the encoding getstatusoutput() uses. status, output = subprocess.getstatusoutput( - ("type " if mswindows else "cat ") + name) + ("type " if mswindows else "cat ") + name, errors="replace") self.assertNotEqual(status, 0) finally: if dir is not None: