Skip to content
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

gh-95027: Fix regrtest stdout encoding on Windows #98492

Merged
merged 1 commit into from Oct 21, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 20, 2022

On Windows, when the Python test suite is run with the -jN option, the ANSI code page is now used as the encoding for the stdout temporary file, rather than using UTF-8 which can lead to decoding errors.

@vstinner
Copy link
Member Author

vstinner commented Oct 20, 2022

I failed to write a test reproducing the bug in test_regrtest, since test_regrtest runs the test suite with stdout being a pipe, which works around the bug :-( I tried to add this test:

    def test_nonascii(self):
        character = chr(0xe9)
        line = f"nonascii: {character}"
        encoding = locale.getencoding()
        try:
            line.encode(encoding)
        except EncodingError:
            self.skipTest(f"fail to encode character U+00E9 "
                          f"to locale encoding {encoding}")

        code = textwrap.dedent(f"""
            import unittest

            class Tests(unittest.TestCase):
                def test_nonascii(self):
                    line = {line!a}
                    print(line)
        """)
        testname = self.create_test(code=code)

        # sequential execution: may use the terminal
        output = self.run_tests(testname)
        self.check_executed_tests(output, [testname])
        self.assertIn(line, output)

        # parallel execution: stdout is a temporary file
        output = self.run_tests("-j1", testname)
        self.check_executed_tests(output, [testname])
        self.assertIn(line, output)

On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
@vstinner
Copy link
Member Author

vstinner commented Oct 20, 2022

@zooba wrote PR #96669 which has more side effects. This PR basically just restores the behavior before commit 199ba23.

@vstinner vstinner merged commit ec1f6f5 into python:main Oct 21, 2022
15 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented Oct 21, 2022

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒🤖

@vstinner vstinner deleted the regrtest_encoding branch Oct 21, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 21, 2022
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member Author

vstinner commented Oct 21, 2022

I would prefer a formal review, but I merged my PR just to unblock the 3.11.0 final release (scheduled next Monday). Maybe if something can be enhanced, it can be done later. IMO this fix is better than the current situation. In short, it just restores the old behavior: encodings used before 199ba23

@miss-islington
Copy link
Contributor

miss-islington commented Oct 21, 2022

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 21, 2022
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner
Copy link
Member Author

vstinner commented Oct 21, 2022

3.11 backport: #98521 (review)

miss-islington added a commit that referenced this pull request Oct 21, 2022
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5)

Co-authored-by: Victor Stinner <vstinner@python.org>
pablogsal pushed a commit that referenced this pull request Oct 24, 2022
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5)

Co-authored-by: Victor Stinner <vstinner@python.org>
pablogsal pushed a commit that referenced this pull request Oct 24, 2022
On Windows, when the Python test suite is run with the -jN option,
the ANSI code page is now used as the encoding for the stdout
temporary file, rather than using UTF-8 which can lead to decoding
errors.
(cherry picked from commit ec1f6f5)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants