summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_regrtest.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-06-28 02:58:34 (GMT)
committerGitHub <noreply@github.com>2023-06-28 02:58:34 (GMT)
commitd5418e97fc524420011a370ba3c2c3cf6a89a74f (patch)
treebaf67ac10d6592efcdeccd4db1d3f9bdcc48da5f /Lib/test/test_regrtest.py
parentfbb0151e5ec14e2db5699bdb7adcc19d3c0b7267 (diff)
downloadcpython-d5418e97fc524420011a370ba3c2c3cf6a89a74f.zip
cpython-d5418e97fc524420011a370ba3c2c3cf6a89a74f.tar.gz
cpython-d5418e97fc524420011a370ba3c2c3cf6a89a74f.tar.bz2
[3.11] gh-101634: regrtest reports decoding error as failed test (#106169) (#106175)
gh-101634: regrtest reports decoding error as failed test (#106169) When running the Python test suite with -jN option, if a worker stdout cannot be decoded from the locale encoding report a failed testn so the exitcode is non-zero. (cherry picked from commit 2ac3eec103cf450aaaebeb932e51155d2e7fb37b)
Diffstat (limited to 'Lib/test/test_regrtest.py')
-rw-r--r--Lib/test/test_regrtest.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index f692dd1..7855259 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -7,6 +7,7 @@ Note: test_regrtest cannot be run twice in parallel.
import contextlib
import glob
import io
+import locale
import os.path
import platform
import re
@@ -1518,6 +1519,41 @@ class ArgsTestCase(BaseTestCase):
for name in names:
self.assertFalse(os.path.exists(name), name)
+ def test_mp_decode_error(self):
+ # gh-101634: If a worker stdout cannot be decoded, report a failed test
+ # and a non-zero exit code.
+ if sys.platform == 'win32':
+ encoding = locale.getencoding()
+ else:
+ encoding = sys.stdout.encoding
+ if encoding is None:
+ encoding = sys.__stdout__.encoding
+ if encoding is None:
+ self.skipTest(f"cannot get regrtest worker encoding")
+
+ nonascii = b"byte:\xa0\xa9\xff\n"
+ try:
+ nonascii.decode(encoding)
+ except UnicodeDecodeError:
+ pass
+ else:
+ self.skipTest(f"{encoding} can decode non-ASCII bytes {nonascii!a}")
+
+ code = textwrap.dedent(fr"""
+ import sys
+ # bytes which cannot be decoded from UTF-8
+ nonascii = {nonascii!a}
+ sys.stdout.buffer.write(nonascii)
+ sys.stdout.buffer.flush()
+ """)
+ testname = self.create_test(code=code)
+
+ output = self.run_tests("--fail-env-changed", "-v", "-j1", testname,
+ exitcode=EXITCODE_BAD_TEST)
+ self.check_executed_tests(output, [testname],
+ failed=[testname],
+ randomize=True)
+
class TestUtils(unittest.TestCase):
def test_format_duration(self):