Skip to content

gh-160652: Make test_getoutput independent of the console code page - #160664

Open
summeriver13 wants to merge 1 commit into
python:mainfrom
summeriver13:fix/test-subprocess-getoutput-encoding
Open

summeriver13 wants to merge 1 commit into
python:mainfrom
summeriver13:fix/test-subprocess-getoutput-encoding

Conversation

@summeriver13

@summeriver13 summeriver13 commented Oct 25, 2026 •

Copy link
Copy Markdown

test_getoutput fails on Windows whenever the console code page is not UTF-8: getstatusoutput() decodes the shell's localized error message as UTF-8 and raises.

File "Lib/subprocess.py", line 1382, in communicate
    stdout = self.stdout.read()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 4

UTF-8 is correct for Python's side of the pipe — the code page is the child's choice, not Python's — but this test only needs the exit status, so let the decoder replace the bytes it cannot decode. That keeps getstatusoutput() under test instead of switching to run(), as suggested in the issue.
Verified on zh-CN Windows 11 (CP936), current main:

# before
$ ./PCbuild/amd64/python_d.exe -m test test_subprocess -m test_getoutput
FAILED (errors=1)
# after
$ ./PCbuild/amd64/python_d.exe -m test test_subprocess -m test_getoutput
OK
$ ./PCbuild/amd64/python_d.exe -m test test_subprocess
Result: SUCCESS (run=371 skipped=216)

3.12 with -X utf8=1 fails the same way, so the test was encoding-dependent since UTF-8 mode existed; 3.15 only made it the default. Skip news (test only).
AI assistance: drafted with deepseek-v4.1-flash in the pi coding agent; commands above were run locally, text reviewed by the author.

Fixes #160652

…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.
@bedevere-app

bedevere-app Bot commented Oct 25, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@aisk aisk added the skip news label Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_subprocess: test_getoutput fails on non-English Windows, as text mode decodes cmd.exe's OEM output as UTF-8

2 participants