Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ac3eec

Browse files
authored
gh-101634: regrtest reports decoding error as failed test (#106169)
When running the Python test suite with -jN option, if a worker stdoutcannot be decoded from the locale encoding report a failed testn so theexitcode is non-zero.
1 parent3f8483c commit2ac3eec

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

‎Lib/test/libregrtest/runtest_mp.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
277277
encoding=locale.getencoding()
278278
else:
279279
encoding=sys.stdout.encoding
280+
280281
# gh-94026: Write stdout+stderr to a tempfile as workaround for
281282
# non-blocking pipes on Emscripten with NodeJS.
282283
withtempfile.TemporaryFile('w+',encoding=encoding)asstdout_fh:
@@ -298,7 +299,14 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
298299
retcode=self._run_process(test_name,None,stdout_fh)
299300
tmp_files= ()
300301
stdout_fh.seek(0)
301-
stdout=stdout_fh.read().strip()
302+
303+
try:
304+
stdout=stdout_fh.read().strip()
305+
exceptExceptionasexc:
306+
# gh-101634: Catch UnicodeDecodeError if stdout cannot be
307+
# decoded from encoding
308+
err_msg=f"Cannot read process stdout:{exc}"
309+
returnself.mp_result_error(ChildError(test_name),'',err_msg)
302310

303311
ifretcodeisNone:
304312
returnself.mp_result_error(Timeout(test_name),stdout)
@@ -481,6 +489,8 @@ def _process_result(self, item: QueueOutput) -> bool:
481489
# Thread got an exception
482490
format_exc=item[1]
483491
print_warning(f"regrtest worker thread failed:{format_exc}")
492+
result=ChildError("<regrtest worker>")
493+
self.regrtest.accumulate_result(result)
484494
returnTrue
485495

486496
self.test_index+=1

‎Lib/test/test_regrtest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
importcontextlib
88
importglob
99
importio
10+
importlocale
1011
importos.path
1112
importplatform
1213
importre
@@ -1551,6 +1552,41 @@ def test_leak_tmp_file(self):
15511552
f"files (1): mytmpfile",
15521553
output)
15531554

1555+
deftest_mp_decode_error(self):
1556+
# gh-101634: If a worker stdout cannot be decoded, report a failed test
1557+
# and a non-zero exit code.
1558+
ifsys.platform=='win32':
1559+
encoding=locale.getencoding()
1560+
else:
1561+
encoding=sys.stdout.encoding
1562+
ifencodingisNone:
1563+
encoding=sys.__stdout__.encoding
1564+
ifencodingisNone:
1565+
self.skipTest(f"cannot get regrtest worker encoding")
1566+
1567+
nonascii=b"byte:\xa0\xa9\xff\n"
1568+
try:
1569+
nonascii.decode(encoding)
1570+
exceptUnicodeDecodeError:
1571+
pass
1572+
else:
1573+
self.skipTest(f"{encoding} can decode non-ASCII bytes{nonascii!a}")
1574+
1575+
code=textwrap.dedent(fr"""
1576+
import sys
1577+
# bytes which cannot be decoded from UTF-8
1578+
nonascii ={nonascii!a}
1579+
sys.stdout.buffer.write(nonascii)
1580+
sys.stdout.buffer.flush()
1581+
""")
1582+
testname=self.create_test(code=code)
1583+
1584+
output=self.run_tests("--fail-env-changed","-v","-j1",testname,
1585+
exitcode=EXITCODE_BAD_TEST)
1586+
self.check_executed_tests(output, [testname],
1587+
failed=[testname],
1588+
randomize=True)
1589+
15541590

15551591
classTestUtils(unittest.TestCase):
15561592
deftest_format_duration(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When running the Python test suite with ``-jN`` option, if a worker stdout
2+
cannot be decoded from the locale encoding report a failed testn so the
3+
exitcode is non-zero. Patch by Victor Stinner.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp