Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r73287:2765b0c6e842
Date: 2014-09-03 16:54 +0200
http://bitbucket.org/pypy/pypy/changeset/2765b0c6e842/

Log:    Be safe: it seems we can get unicode strings here, and the print_()
        function just calls str(x) on them.

diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py
--- a/_pytest/resultlog.py
+++ b/_pytest/resultlog.py
@@ -54,15 +54,15 @@
         self.logfile = logfile # preferably line buffered
 
     def write_log_entry(self, testpath, lettercode, longrepr, sections=None):
-        py.builtin.print_("%s %s" % (lettercode, testpath), file=self.logfile)
+        _safeprint("%s %s" % (lettercode, testpath), file=self.logfile)
         for line in longrepr.splitlines():
-            py.builtin.print_(" %s" % line, file=self.logfile)
+            _safeprint(" %s" % line, file=self.logfile)
         if sections is not None:
             for title, content in sections:
-                py.builtin.print_(" ---------- %s ----------" % (title,),
-                                  file=self.logfile)
+                _safeprint(" ---------- %s ----------" % (title,),
+                           file=self.logfile)
                 for line in content.splitlines():
-                    py.builtin.print_(" %s" % line, file=self.logfile)
+                    _safeprint(" %s" % line, file=self.logfile)
 
     def log_outcome(self, report, lettercode, longrepr):
         testpath = getattr(report, 'nodeid', None)
@@ -105,3 +105,8 @@
         if path is None:
             path = "cwd:%s" % py.path.local()
         self.write_log_entry(path, '!', str(excrepr))
+
+def _safeprint(s, file):
+    if isinstance(s, unicode):
+        s = s.encode('utf-8')
+    py.builtin.print_(s)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to