Set PYTHONIOENCODING when running tests

For instance, on Windows, if the terminal is in cp65001, the subprocess
output is not encoded correctly and it results in error when running
unit test.
pull/12910/head
Charles Brunet 9 months ago committed by Dylan Baker
parent c67a6e1d7c
commit 4ed6d75d96
  1. 2
      unittests/allplatformstests.py
  2. 1
      unittests/baseplatformtests.py

@ -471,7 +471,7 @@ class AllPlatformTests(BasePlatformTests):
# Ensure command output and JSON / text logs are not mangled.
raw_output_sample = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b'
assert raw_output_sample in tests_command_output
text_log = Path(self.logdir, 'testlog.txt').read_text()
text_log = Path(self.logdir, 'testlog.txt').read_text(encoding='utf-8')
assert raw_output_sample in text_log
json_log = json.loads(Path(self.logdir, 'testlog.json').read_bytes())
assert raw_output_sample in json_log['stdout']

@ -85,6 +85,7 @@ class BasePlatformTests(TestCase):
# XCode backend is untested with unit tests, help welcome!
self.no_rebuild_stdout = [f'UNKNOWN BACKEND {self.backend.name!r}']
os.environ['COLUMNS'] = '80'
os.environ['PYTHONIOENCODING'] = 'utf8'
self.builddirs = []
self.new_builddir()

Loading…
Cancel
Save