Skip to content

Commit ce45e98

Browse files
vstinnermiss-islington
authored andcommitted
gh-95027: Fix regrtest stdout encoding on Windows (GH-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. (cherry picked from commit ec1f6f5) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 0bc2cf9 commit ce45e98

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Lib/test/libregrtest/runtest_mp.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
from test.libregrtest.setup import setup_tests
2222
from test.libregrtest.utils import format_duration, print_warning
2323

24+
if sys.platform == 'win32':
25+
import locale
26+
2427

2528
# Display the running tests if nothing happened last N seconds
2629
PROGRESS_UPDATE = 30.0 # seconds
@@ -259,11 +262,16 @@ def _run_process(self, test_name: str, stdout_fh: TextIO) -> int:
259262
self.current_test_name = None
260263

261264
def _runtest(self, test_name: str) -> MultiprocessResult:
265+
if sys.platform == 'win32':
266+
# gh-95027: When stdout is not a TTY, Python uses the ANSI code
267+
# page for the sys.stdout encoding. If the main process runs in a
268+
# terminal, sys.stdout uses WindowsConsoleIO with UTF-8 encoding.
269+
encoding = locale.getencoding()
270+
else:
271+
encoding = sys.stdout.encoding
262272
# gh-94026: Write stdout+stderr to a tempfile as workaround for
263273
# non-blocking pipes on Emscripten with NodeJS.
264-
with tempfile.TemporaryFile(
265-
'w+', encoding=sys.stdout.encoding
266-
) as stdout_fh:
274+
with tempfile.TemporaryFile('w+', encoding=encoding) as stdout_fh:
267275
# gh-93353: Check for leaked temporary files in the parent process,
268276
# since the deletion of temporary files can happen late during
269277
# Python finalization: too late for libregrtest.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
On Windows, when the Python test suite is run with the ``-jN`` option, the
2+
ANSI code page is now used as the encoding for the stdout temporary file,
3+
rather than using UTF-8 which can lead to decoding errors. Patch by Victor
4+
Stinner.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy