Skip to content

regrtest can fail writing unencodable test description or status #135124

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
serhiy-storchaka opened this issue Jun 4, 2025 · 3 comments
Closed
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes stdlib Python modules in the Lib dir tests Tests in the Lib/test dir topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jun 4, 2025

Bug report

I already fixed errors related to non-ASCII skip messages (by using ascii() instead of str() or repr()). There may be other non-ASCII skip messages left, but they are not raised on buildbots with non-UTF-8 stdout. In any case, this only fixed CPython tests, user tests can have the same issues.

#135121 exposed a new issue -- subtest description which includes non-ASCII parameter values. It is more difficult, because we have no control on formatting them. Always using ascii() instead of repr() will harm readability on normal platforms.

Linked PRs

@serhiy-storchaka serhiy-storchaka added the type-bug An unexpected behavior, bug, or error label Jun 4, 2025
@serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir topic-unicode 3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes labels Jun 4, 2025
@serhiy-storchaka
Copy link
Member Author

The following tests passes in unittest and in libregrtest with a single process, but fails in libregrtest with multiple processes.

import unittest
class TestNonASCII(unittest.TestCase):
    def test_docstring(self):
        """\u20ac"""
    def test_subtest(self):
        with self.subTest(param='\u20ac'):
            pass
    def test_skip(self):
        self.skipTest('\u20ac')

When run with unittest, the output stream is stderr with the backslashreplace error handler. In libregrtest with a single process, the output stream is stdout with the backslashreplace error handler, but in multi-process mode -- with the strict error handler.

@serhiy-storchaka
Copy link
Member Author

cc @vstinner

vstinner added a commit to vstinner/cpython that referenced this issue Jun 4, 2025
Set sys.stdout encoder error handler to backslashreplace in regrtest
to avoid UnicodeEncodeError when printing a traceback or any other
non-encodable character.

Move the code from the Regrtest class to test.libregrtest.setup
module.

Call setup_process() before displaying regrtest headers.
vstinner added a commit to vstinner/cpython that referenced this issue Jun 4, 2025
Set sys.stdout encoder error handler to backslashreplace in regrtest
to avoid UnicodeEncodeError when printing a traceback or any other
non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() before displaying regrtest headers.
vstinner added a commit to vstinner/cpython that referenced this issue Jun 4, 2025
Set sys.stdout encoder error handler to backslashreplace in regrtest
to avoid UnicodeEncodeError when printing a traceback or any other
non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() before displaying regrtest headers.
@vstinner
Copy link
Member

vstinner commented Jun 4, 2025

I proposed #135138 to fix the issue.

@serhiy-storchaka serhiy-storchaka added the tests Tests in the Lib/test dir label Jun 4, 2025
@serhiy-storchaka serhiy-storchaka changed the title unittest can fail writing unencodable test description or status regrtest can fail writing unencodable test description or status Jun 4, 2025
vstinner added a commit that referenced this issue Jun 5, 2025
Set sys.stdout encoder error handler to backslashreplace in regrtest
workers to avoid UnicodeEncodeError when printing a traceback
or any other non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() earlier, before displaying regrtest headers.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 5, 2025
…honGH-135138)

Set sys.stdout encoder error handler to backslashreplace in regrtest
workers to avoid UnicodeEncodeError when printing a traceback
or any other non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() earlier, before displaying regrtest headers.
(cherry picked from commit 3d396ab)

Co-authored-by: Victor Stinner <vstinner@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 5, 2025
…honGH-135138)

Set sys.stdout encoder error handler to backslashreplace in regrtest
workers to avoid UnicodeEncodeError when printing a traceback
or any other non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() earlier, before displaying regrtest headers.
(cherry picked from commit 3d396ab)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner vstinner closed this as completed Jun 5, 2025
vstinner added a commit that referenced this issue Jun 5, 2025
…-135138) (#135168)

gh-135124: Change stdout errors in regrtest worker process (GH-135138)

Set sys.stdout encoder error handler to backslashreplace in regrtest
workers to avoid UnicodeEncodeError when printing a traceback
or any other non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() earlier, before displaying regrtest headers.
(cherry picked from commit 3d396ab)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this issue Jun 5, 2025
…-135138) (#135169)

gh-135124: Change stdout errors in regrtest worker process (GH-135138)

Set sys.stdout encoder error handler to backslashreplace in regrtest
workers to avoid UnicodeEncodeError when printing a traceback
or any other non-encodable character.

Move the code from the Regrtest class to setup_process().

Call setup_process() earlier, before displaying regrtest headers.
(cherry picked from commit 3d396ab)

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
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes stdlib Python modules in the Lib dir tests Tests in the Lib/test dir topic-unicode type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants