diff --git a/_pytest/assertion/reinterpret.py b/_pytest/assertion/reinterpret.py index c598ec882..88fbb31a5 100644 --- a/_pytest/assertion/reinterpret.py +++ b/_pytest/assertion/reinterpret.py @@ -11,7 +11,7 @@ class AssertionError(BuiltinAssertionError): self.msg = py.builtin._totext(args[0]) except Exception: self.msg = py.builtin._totext( - "<[broken __repr__] %s at %0xd> %s" + "<[broken __repr__] %s at %0xd>" % (args[0].__class__, id(args[0]))) else: f = py.code.Frame(sys._getframe(1)) diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 759385011..1787e7354 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -127,7 +127,7 @@ except NameError: def assertrepr_compare(config, op, left, right): """Return specialised explanations for some operators/operands""" width = 80 - 15 - len(op) - 2 # 15 chars indentation, 1 space around op - left_repr = py.io.saferepr(left, maxsize=int(width/2)) # XXX mangles unicode + left_repr = py.io.saferepr(left, maxsize=int(width/2)) right_repr = py.io.saferepr(right, maxsize=width-len(left_repr)) summary = u('%s %s %s') % (left_repr, op, right_repr) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 028cffe3b..2a18bbf01 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import sys import py, pytest @@ -176,6 +177,15 @@ class TestAssert_reprcompare: expl = ' '.join(callequal('foo', 'bar')) assert 'raised in repr()' not in expl + def test_unicode(self): + left = py.builtin._totext('£€', 'utf-8') + right = py.builtin._totext('£', 'utf-8') + expl = callequal(left, right) + assert expl[0] == py.builtin._totext("'£€' == '£'", 'utf-8') + assert expl[1] == py.builtin._totext('- £€', 'utf-8') + assert expl[2] == py.builtin._totext('+ £', 'utf-8') + + def test_python25_compile_issue257(testdir): testdir.makepyfile(""" def test_rewritten():