From f1eab2a8eb385b678cbb3e0b6043b2231346e4e6 Mon Sep 17 00:00:00 2001 From: Adnan Waheed Date: Fri, 3 May 2019 16:38:29 +0200 Subject: [PATCH] Use 'utf-8' encoding for exception info if there is no encoding set for sys.stdout On some systems encoding for sys.stdout is defined but is None. In this case the default utf-8 is not used as getattr() will find the attrbute but because it is None, we get an exception when we try to encode a line. --- xmlrunner/result.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xmlrunner/result.py b/xmlrunner/result.py index 1b7cce6..62b97b6 100644 --- a/xmlrunner/result.py +++ b/xmlrunner/result.py @@ -693,6 +693,8 @@ def _exc_info_to_string(self, err, test): msgLines.append(STDERR_LINE % error) # This is the extra magic to make sure all lines are str encoding = getattr(sys.stdout, 'encoding', 'utf-8') + if encoding is None: + encoding = 'utf-8' lines = [] for line in msgLines: if not isinstance(line, str):