Skip to content

Commit 856ad71

Browse files
committed
Fix UnicodeEncodeError when string comparison with unicode has failed.
1 parent 9c45d6c commit 856ad71

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

_pytest/_code/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def __init__(self, tup=None, exprinfo=None):
354354
if exprinfo is None and isinstance(tup[1], AssertionError):
355355
exprinfo = getattr(tup[1], 'msg', None)
356356
if exprinfo is None:
357-
exprinfo = str(tup[1])
357+
exprinfo = py._builtin._totext(tup[1])
358358
if exprinfo and exprinfo.startswith('assert '):
359359
self._striptext = 'AssertionError: '
360360
self._excinfo = tup

testing/test_assertion.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,3 +816,12 @@ def test_tuple():
816816
result = testdir.runpytest('-rw')
817817
output = '\n'.join(result.stdout.lines)
818818
assert 'WR1' not in output
819+
820+
def test_assert_with_unicode(monkeypatch, testdir):
821+
testdir.makepyfile(u"""
822+
# -*- coding: utf-8 -*-
823+
def test_unicode():
824+
assert u'유니코드' == u'Unicode'
825+
""")
826+
result = testdir.runpytest()
827+
result.stdout.fnmatch_lines(['*AssertionError*'])

0 commit comments

Comments
 (0)