From 78d67c007ba836cef96ce7a4418c65ae9f51a188 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 28 Apr 2010 17:19:49 -0500 Subject: [PATCH] be more robust about bad std stream encodings --HG-- branch : trunk --- py/_plugin/pytest_pytester.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/py/_plugin/pytest_pytester.py b/py/_plugin/pytest_pytester.py index f2375eeba..20cac915c 100644 --- 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):