Skip to content

Commit 204b71a

Browse files
committed
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.
1 parent 1159836 commit 204b71a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎Lib/test/test_subprocess.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4132,8 +4132,10 @@ def test_getoutput(self):
41324132
try:
41334133
dir = tempfile.mkdtemp()
41344134
name = os.path.join(dir, "foo")
4135+
# The message comes from the shell in the console code page,
4136+
# which need not be the encoding getstatusoutput() uses.
41354137
status, output = subprocess.getstatusoutput(
4136-
("type " if mswindows else "cat ") + name)
4138+
("type " if mswindows else "cat ") + name, errors="replace")
41374139
self.assertNotEqual(status, 0)
41384140
finally:
41394141
if dir is not None:

0 commit comments

Comments
 (0)