From 04e2f41783d7edc95cade17eb4e6808ee7bb8144 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Thu, 2 Jan 2020 14:41:09 +0100 Subject: [PATCH] test: fix unit test logging with python3 A logfile must be opened as a text file and encoding is specified. Then it can accept a string. Current behaviour we get, Message: 'ok 2834 sequential/test-worker-prof' Arguments: () --- Logging error --- Traceback (most recent call last): File "/usr/lib64/python3.7/logging/__init__.py", line 1037, in emit stream.write(msg + self.terminator) TypeError: a bytes-like object is required, not 'str' Call stack: File "tools/test.py", line 1734, in sys.exit(Main()) File "tools/test.py", line 1710, in Main if RunTestCases(cases_to_run, options.progress, options.j, options.flaky_tests): File "tools/test.py", line 933, in RunTestCases return progress.Run(tasks) File "tools/test.py", line 141, in Run self.RunSingle(False, 0) File "tools/test.py", line 202, in RunSingle self.HasRun(output) File "tools/test.py", line 365, in HasRun logger.info(' ---') PR-URL: https://github.com/nodejs/node/pull/31156 Reviewed-By: Christian Clauss Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Richard Lau Reviewed-By: David Carlier Reviewed-By: Rich Trott Reviewed-By: Daijiro Wachi --- tools/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test.py b/tools/test.py index 8a7e8987bd1f8e..71a754091ad292 100755 --- a/tools/test.py +++ b/tools/test.py @@ -1529,7 +1529,7 @@ def Main(): logger.addHandler(ch) logger.setLevel(logging.INFO) if options.logfile: - fh = logging.FileHandler(options.logfile, mode='wb') + fh = logging.FileHandler(options.logfile, encoding='utf-8', mode='w') logger.addHandler(fh) workspace = abspath(join(dirname(sys.argv[0]), '..'))