mirror of
https://github.com/python/cpython.git
synced 2025-09-28 11:15:17 +00:00
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 ec1f6f5f13
)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
0bc2cf9915
commit
b2aa28eec5
2 changed files with 15 additions and 3 deletions
|
@ -21,6 +21,9 @@ from test.libregrtest.runtest import (
|
||||||
from test.libregrtest.setup import setup_tests
|
from test.libregrtest.setup import setup_tests
|
||||||
from test.libregrtest.utils import format_duration, print_warning
|
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
|
# Display the running tests if nothing happened last N seconds
|
||||||
PROGRESS_UPDATE = 30.0 # seconds
|
PROGRESS_UPDATE = 30.0 # seconds
|
||||||
|
@ -259,11 +262,16 @@ class TestWorkerProcess(threading.Thread):
|
||||||
self.current_test_name = None
|
self.current_test_name = None
|
||||||
|
|
||||||
def _runtest(self, test_name: str) -> MultiprocessResult:
|
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
|
# gh-94026: Write stdout+stderr to a tempfile as workaround for
|
||||||
# non-blocking pipes on Emscripten with NodeJS.
|
# non-blocking pipes on Emscripten with NodeJS.
|
||||||
with tempfile.TemporaryFile(
|
with tempfile.TemporaryFile('w+', encoding=encoding) as stdout_fh:
|
||||||
'w+', encoding=sys.stdout.encoding
|
|
||||||
) as stdout_fh:
|
|
||||||
# gh-93353: Check for leaked temporary files in the parent process,
|
# gh-93353: Check for leaked temporary files in the parent process,
|
||||||
# since the deletion of temporary files can happen late during
|
# since the deletion of temporary files can happen late during
|
||||||
# Python finalization: too late for libregrtest.
|
# Python finalization: too late for libregrtest.
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
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. Patch by Victor
|
||||||
|
Stinner.
|
Loading…
Add table
Add a link
Reference in a new issue