Skip to content

Commit

Permalink
Revert "[3.11] pythongh-101634: regrtest reports decoding error as fa…
Browse files Browse the repository at this point in the history
…iled test (python#106169) (python#106175)"

This reverts commit d5418e9.
  • Loading branch information
vstinner committed Sep 2, 2023
1 parent 662d236 commit a4e5e7b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
12 changes: 1 addition & 11 deletions Lib/test/libregrtest/runtest_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ 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 @@ -278,14 +277,7 @@ 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)

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)
stdout = stdout_fh.read().strip()

if retcode is None:
return self.mp_result_error(Timeout(test_name), stdout)
Expand Down Expand Up @@ -460,8 +452,6 @@ 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: 0 additions & 36 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import contextlib
import glob
import io
import locale
import os.path
import platform
import re
Expand Down Expand Up @@ -1519,41 +1518,6 @@ 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

0 comments on commit a4e5e7b

Please sign in to comment.