diff options
author | Victor Stinner <vstinner@python.org> | 2022-10-21 14:21:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 14:21:36 (GMT) |
commit | ec1f6f5f139868dc2c1116a7c7c878c38c668d53 (patch) | |
tree | f610a4e94ffd2a881a38e4ad4f6eca61f735c346 /Lib | |
parent | 82ccbf69a842db25d8117f1c41b47aa5b4ed96ab (diff) | |
download | cpython-ec1f6f5f139868dc2c1116a7c7c878c38c668d53.zip cpython-ec1f6f5f139868dc2c1116a7c7c878c38c668d53.tar.gz cpython-ec1f6f5f139868dc2c1116a7c7c878c38c668d53.tar.bz2 |
gh-95027: Fix regrtest stdout encoding on Windows (#98492)
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/libregrtest/runtest_mp.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py index a4d3e5c..a12fcb4 100644 --- a/Lib/test/libregrtest/runtest_mp.py +++ b/Lib/test/libregrtest/runtest_mp.py @@ -22,6 +22,9 @@ from test.libregrtest.runtest import ( from test.libregrtest.setup import setup_tests from test.libregrtest.utils import format_duration, print_warning +if sys.platform == 'win32': + import locale + # Display the running tests if nothing happened last N seconds PROGRESS_UPDATE = 30.0 # seconds @@ -267,11 +270,16 @@ class TestWorkerProcess(threading.Thread): self.current_test_name = None def _runtest(self, test_name: str) -> MultiprocessResult: + if sys.platform == 'win32': + # gh-95027: When stdout is not a TTY, Python uses the ANSI code + # page for the sys.stdout encoding. If the main process runs in a + # terminal, sys.stdout uses WindowsConsoleIO with UTF-8 encoding. + encoding = locale.getencoding() + else: + encoding = sys.stdout.encoding # gh-94026: Write stdout+stderr to a tempfile as workaround for # non-blocking pipes on Emscripten with NodeJS. - with tempfile.TemporaryFile( - 'w+', encoding=sys.stdout.encoding - ) as stdout_fh: + with tempfile.TemporaryFile('w+', encoding=encoding) as stdout_fh: # gh-93353: Check for leaked temporary files in the parent process, # since the deletion of temporary files can happen late during # Python finalization: too late for libregrtest. |