Skip to content

Commit c6a2dcc

Browse files
#877 - reencoding causes typeerrors on python2
1 parent 28eceb5 commit c6a2dcc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

_pytest/assertion/util.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ def assertrepr_compare(config, op, left, right):
130130
left_repr = py.io.saferepr(left, maxsize=int(width/2))
131131
right_repr = py.io.saferepr(right, maxsize=width-len(left_repr))
132132

133-
# the reencoding is needed for python2 repr
134-
# with non-ascii characters (see isssue 877)
135-
summary = u('%s %s %s') % (
136-
u(left_repr, 'utf-8', 'replace'),
137-
op,
138-
u(right_repr, 'utf-8', 'replace'),
139-
)
133+
# the re-encoding is needed for python2 repr
134+
# with non-ascii characters (see issue 877)
135+
def ecu(s):
136+
try:
137+
return u(s, 'utf-8', 'replace')
138+
except TypeError:
139+
return s
140+
141+
summary = u('%s %s %s') % (ecu(left_repr), op, ecu(right_repr))
140142

141143
issequence = lambda x: (isinstance(x, (list, tuple, Sequence))
142144
and not isinstance(x, basestring))

0 commit comments

Comments
 (0)