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

[3.11] gh-101634: regrtest reports decoding error as failed test (#106169)#106175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:3.11fromvstinner:regrtest311
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.(cherry picked from commit2ac3eec)
  • Loading branch information
@vstinner
vstinner committedJun 28, 2023
commit7d61c967c9663d12deb7c7de2b48e17d6041308d
12 changes: 11 additions & 1 deletionLib/test/libregrtest/runtest_mp.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,6 +269,7 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
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=encoding) as stdout_fh:
Expand All@@ -277,7 +278,14 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
# Python finalization: too late for libregrtest.
retcode = self._run_process(test_name, stdout_fh)
stdout_fh.seek(0)
stdout = stdout_fh.read().strip()

try:
stdout = stdout_fh.read().strip()
except Exception as exc:
# gh-101634: Catch UnicodeDecodeError if stdout cannot be
# decoded from encoding
err_msg = f"Cannot read process stdout: {exc}"
return self.mp_result_error(ChildError(test_name), '', err_msg)

if retcode is None:
return self.mp_result_error(Timeout(test_name), stdout)
Expand DownExpand Up@@ -452,6 +460,8 @@ def _process_result(self, item: QueueOutput) -> bool:
# Thread got an exception
format_exc = item[1]
print_warning(f"regrtest worker thread failed: {format_exc}")
result = ChildError("<regrtest worker>")
self.regrtest.accumulate_result(result)
return True

self.test_index += 1
Expand Down
36 changes: 36 additions & 0 deletionsLib/test/test_regrtest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@
import contextlib
import glob
import io
import locale
import os.path
import platform
import re
Expand DownExpand Up@@ -1518,6 +1519,41 @@ def test_cleanup(self):
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):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
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. Patch by Victor Stinner.

[8]ページ先頭

©2009-2025 Movatter.jp