Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (revision 83356) +++ Lib/doctest.py (working copy) @@ -239,6 +239,16 @@ class _SpoofOut(StringIO): def getvalue(self): result = StringIO.getvalue(self) + if isinstance(self.buf, unicode): + # The doctest text file paths will be 8bit. + # Thus any Unicode in the buffer needs to be converted + # to 8bit before the values in self.buflist are + # added to self.buf. + self.buf = self.buf.encode(sys.getfilesystemencoding()) + if self.buflist: + self.buf += ''.join(self.buflist) + self.buflist = [] + result = self.buf # If anything at all was written, make sure there's a trailing # newline. There's no way for the expected output to indicate # that a trailing newline is missing.