[py-svn] py-trunk commit d42910531b64: be more robust about bad std stream encodings

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Apr 29 00:21:58 CEST 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User Benjamin Peterson <benjamin at python.org>
# Date 1272493189 18000
# Node ID d42910531b648556b0473dd6c07f7896476a8bc5
# Parent  bce06f772dce796c5b5a43df9abdfabbf5afd7ff
be more robust about bad std stream encodings

--- a/py/_plugin/pytest_pytester.py
+++ b/py/_plugin/pytest_pytester.py
@@ -296,12 +296,14 @@ class TmpTestdir:
         f2.close()
         out = p1.read("rb").decode("utf-8").splitlines()
         err = p2.read("rb").decode("utf-8").splitlines()
-        if err:
-            for line in err:
-                py.builtin.print_(line, file=sys.stderr)
-        if out:
-            for line in out:
-                py.builtin.print_(line, file=sys.stdout)
+        def dump_lines(lines, fp):
+            try:
+                for line in lines:
+                    py.builtin.print_(line, file=fp)
+            except UnicodeEncodeError:
+                print("couldn't print to %s because of encoding" % (fp,))
+        dump_lines(out, sys.stdout)
+        dump_lines(err, sys.stderr)
         return RunResult(ret, out, err, time.time()-now)
 
     def runpybin(self, scriptname, *args):



More information about the pytest-commit mailing list