On Python 2, sys.stdout and print can normally handle any combination of str and unicode objects. However, StringIO.StringIO can only safely handle one or the other. If the program writes both a unicode string, and a non-ASCII str string, then the getvalue() method will fail with UnicodeDecodeError [1].
In nose, that causes the script to suddenly abort, with the cryptic UnicodeDecodeError.
This fix catches UnicodeError when trying to get the captured output, and will replace the captured output with a warning message.
On Python 2,
sys.stdout
andprint
can normally handle any combination ofstr
andunicode
objects. However,StringIO.StringIO
can only safely handle one or the other. If the program writes both aunicode
string, and a non-ASCIIstr
string, then thegetvalue()
method will fail withUnicodeDecodeError
[1].In nose, that causes the script to suddenly abort, with the cryptic
UnicodeDecodeError
.This fix catches
UnicodeError
when trying to get the captured output, and will replace the captured output with a warning message.Fixes #816
[1] https://github.com/python/cpython/blob/2.7/Lib/StringIO.py#L258