diff --git a/scripts/pylib/twister/scl.py b/scripts/pylib/twister/scl.py index bbd9f6d19d0..25a3210b141 100644 --- a/scripts/pylib/twister/scl.py +++ b/scripts/pylib/twister/scl.py @@ -41,7 +41,7 @@ def yaml_load(filename): :return: dictionary representing the YAML document """ try: - with open(filename, 'r') as f: + with open(filename, 'r', encoding='utf-8') as f: return yaml.load(f, Loader=SafeLoader) except yaml.scanner.ScannerError as e: # For errors parsing schema.yaml mark = e.problem_mark diff --git a/scripts/pylib/twister/twisterlib/handlers.py b/scripts/pylib/twister/twisterlib/handlers.py index b5ba721a2fb..372a8b019dc 100755 --- a/scripts/pylib/twister/twisterlib/handlers.py +++ b/scripts/pylib/twister/twisterlib/handlers.py @@ -355,7 +355,7 @@ class DeviceHandler(Handler): super().__init__(instance, type_str) def monitor_serial(self, ser, halt_event, harness): - log_out_fp = open(self.log, "wt") + log_out_fp = open(self.log, "wb") if self.options.coverage: # Set capture_coverage to True to indicate that right after @@ -407,7 +407,7 @@ class DeviceHandler(Handler): sl = serial_line.decode('utf-8', 'ignore').lstrip() logger.debug("DEVICE: {0}".format(sl.rstrip())) - log_out_fp.write(sl) + log_out_fp.write(sl.encode('utf-8')) log_out_fp.flush() harness.handle(sl.rstrip()) diff --git a/scripts/tests/twister/test_scl.py b/scripts/tests/twister/test_scl.py index e334df17e2b..14a0c447192 100644 --- a/scripts/tests/twister/test_scl.py +++ b/scripts/tests/twister/test_scl.py @@ -162,7 +162,7 @@ def test_yaml_load(caplog, fail_parsing): with pytest.raises(ScannerError) if fail_parsing else nullcontext(): result = scl.yaml_load(filename) - mock_file.assert_called_with('dummy/file.yaml', 'r') + mock_file.assert_called_with('dummy/file.yaml', 'r', encoding='utf-8') if not fail_parsing: assert result == result_mock