Skip to content

Commit

Permalink
pythongh-95027: Ensure test runner uses utf-8:surrogateescape for com…
Browse files Browse the repository at this point in the history
…municating with subprocesses
  • Loading branch information
zooba committed Sep 7, 2022
1 parent 9e4179b commit eb1fe90
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ def main(self, tests=None, **kwargs):

self.fix_umask()

# We may have been launched with a certain IO encoding, but we do not
# want children to inherit it, so clear it out now.
os.unsetenv('PYTHONIOENCODING')

if self.ns.cleanup:
self.cleanup()
sys.exit(0)
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/libregrtest/runtest_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def run_test_in_subprocess(testname: str, ns: Namespace, tmp_dir: str, stdout_fh
'-m', 'test.regrtest',
'--worker-args', worker_args]


env = dict(os.environ)
env['PYTHONIOENCODING'] = 'utf-8:surrogateescape'
if tmp_dir is not None:
env['TMPDIR'] = tmp_dir
env['TEMP'] = tmp_dir
Expand Down Expand Up @@ -270,7 +272,7 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
# gh-94026: Write stdout+stderr to a tempfile as workaround for
# non-blocking pipes on Emscripten with NodeJS.
with tempfile.TemporaryFile(
'w+', encoding=sys.stdout.encoding
'w+', encoding=sys.stdout.encoding, errors="surrogateescape",
) as stdout_fh:
# gh-93353: Check for leaked temporary files in the parent process,
# since the deletion of temporary files can happen late during
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensures test runner uses UTF-8 and surrogateescape encoding when
communicating between multiple processes.

0 comments on commit eb1fe90

Please sign in to comment.