Skip to content

test_python_legacy_windows_stdio in test_cmd_line isn't actually working #133374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aisk opened this issue May 4, 2025 · 1 comment
Closed

test_python_legacy_windows_stdio in test_cmd_line isn't actually working #133374

aisk opened this issue May 4, 2025 · 1 comment
Labels
OS-windows tests Tests in the Lib/test dir

Comments

@aisk
Copy link
Contributor

aisk commented May 4, 2025

PYTHONLEGACYWINDOWSSTDIO will let Windows use old console IO for stdin and stdout, and sys.stdin.encoding will become cp instead of utf-8.

def test_python_legacy_windows_stdio(self):
code = "import sys; print(sys.stdin.encoding, sys.stdout.encoding)"
expected = 'cp'
rc, out, err = assert_python_ok('-c', code, PYTHONLEGACYWINDOWSSTDIO='1')
self.assertIn(expected.encode(), out)

In this test, it sets PYTHONLEGACYWINDOWSSTDIO to 1 and creates a new Python process to check if sys.stdin.encoding is cp. However, the new process is created by subprocess.Popen with stdin=PIPE, stdout=PIPE, thus the sys.stdin and sys.stdout will not be console IO, so their encoding is always the current console code page (cp) whether PYTHONLEGACYWINDOWSSTDIO is set or not. So actually nothing has been tested.

Another issue with this test is that it expects the encoding to be cp, but on some non-English locale Windows environments, for example, Simplified Chinese locale, it will be gbk, and the test will fail.

A fix is on the way.

Linked PRs

@chris-eibl
Copy link
Member

Another issue with this test is that it expects the encoding to be cp, but on some non-English locale Windows environments, for example, Simplified Chinese locale, it will be gbk, and the test will fail.

Another issue where the gbk encoding breaks a test: #132143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

3 participants