Index: Lib/unittest/runner.py =================================================================== --- Lib/unittest/runner.py (revision 85314) +++ Lib/unittest/runner.py (working copy) @@ -2,6 +2,8 @@ import sys import time +import io +import os from . import result from .signals import registerResult @@ -12,6 +14,17 @@ class _WritelnDecorator(object): """Used to decorate file-like objects with a handy 'writeln' method""" def __init__(self,stream): + if stream.errors != "backslashreplace": + fd = os.dup(stream.fileno()) + try: + buf = io.open(fd, "wb") + except: + os.close(fd) + raise + buf.raw.name = stream.name + line_buffering = buf.raw.isatty() + stream = io.TextIOWrapper(buf, + stream.encoding, "backslashreplace", "\n", line_buffering) self.stream = stream def __getattr__(self, attr):