From 4ed6d75d962b3d43a9f7e8f5154e48d0bef01cc9 Mon Sep 17 00:00:00 2001 From: Charles Brunet Date: Wed, 28 Feb 2024 11:58:29 -0500 Subject: 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. --- unittests/allplatformstests.py | 2 +- unittests/baseplatformtests.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index bfd0b1856..777f2f92a 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.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'] diff --git a/unittests/baseplatformtests.py b/unittests/baseplatformtests.py index ec3f18908..6125ed933 100644 --- a/unittests/baseplatformtests.py +++ b/unittests/baseplatformtests.py @@ -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() -- cgit v1.2.3