Skip to content

Commit a947e83

Browse files
authored
Merge pull request #1870 from AiOO/bugfix/assertion-with-unicode
Fix UnicodeEncodeError when string comparison with unicode has failed.
2 parents 9c45d6c + 86b8801 commit a947e83

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Contributors include::
55

66
Abdeali JK
77
Abhijeet Kasurde
8+
Ahn Ki-Wook
89
Alexei Kozlenok
910
Anatoly Bubenkoff
1011
Andreas Zeidler

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
* Add ``buffer`` attribute to stdin stub class ``pytest.capture.DontReadFromInput``
1010
Thanks `@joguSD`_ for the PR.
1111

12+
* Fix ``UnicodeEncodeError`` when string comparison with unicode has failed. (`#1864`_)
13+
Thanks `@AiOO`_ for the PR
14+
1215
*
1316

1417
.. _@joguSD: https://github.com/joguSD
18+
.. _@AiOO: https://github.com/AiOO
1519

1620
.. _#1857: https://github.com/pytest-dev/pytest/issues/1857
21+
.. _#1864: https://github.com/pytest-dev/pytest/issues/1864
1722

1823

1924
3.0.1

_pytest/_code/code.py

+1-1
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

+9
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)