Skip to content

test_python_legacy_windows_stdio in test_cmd_line isn't actually working #133374

Closed
@aisk

Description

@aisk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions