testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00744
[Bug 804122] Re: UnicodeEncodeError in TextTestResult._show_list with UTF-8 terminal
** Changed in: testtools
Status: In Progress => Fix Committed
** Changed in: testtools
Milestone: None => next
--
You received this bug notification because you are a member of testtools
developers, which is subscribed to testtools.
https://bugs.launchpad.net/bugs/804122
Title:
UnicodeEncodeError in TextTestResult._show_list with UTF-8 terminal
Status in testtools:
Fix Committed
Bug description:
When testtools tries to display non-ascii unicode output on terminals
that claim to have a unicode encoding, it falls over with an error
like:
Traceback (most recent call last):
File "testtools_unicode.py", line 13, in <module>
main(["run.py", "__main__.Tests"], sys.stdout)
File "testtools/run.py", line 329, in main
program = TestProgram(argv=argv, testRunner=runner, stdout=stdout)
File "testtools/run.py", line 173, in __init__
self.runTests()
File "testtools/run.py", line 322, in runTests
self.result = testRunner.run(self.test)
File "testtools/run.py", line 48, in run
result.stopTestRun()
File "testtools/testresult/real.py", line 308, in stopTestRun
self._show_list('FAIL', self.failures)
File "testtools/testresult/real.py", line 294, in _show_list
self.stream.write(output)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 793: ordinal not in range(128)
This is due to a misunderstanding in
testtools.compat.unicode_output_stream over what the builtin python
streams will actually do. When using a print statement, the stream
will encode unicode using the stream's encoding, but when using the
write method, the 'default' encoding gets used. So, the special case
to skip the wrapper for streams with unicode encodings is incorrect,
all streams need wrapping if we want to be able to pass unicode
objects to write.
This was also a symptom in bug 672056 which was further confused by
some doctest oddness.
To manage notifications about this bug go to:
https://bugs.launchpad.net/testtools/+bug/804122/+subscriptions
References