diff --git a/AUTHORS b/AUTHORS index 8bbb98d9c..043de70c1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,6 +5,7 @@ Contributors include:: Abdeali JK Abhijeet Kasurde +Ahn Ki-Wook Alexei Kozlenok Anatoly Bubenkoff Andreas Zeidler diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 447b03b94..a1aea9bbd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,11 +9,16 @@ * Add ``buffer`` attribute to stdin stub class ``pytest.capture.DontReadFromInput`` Thanks `@joguSD`_ for the PR. +* Fix ``UnicodeEncodeError`` when string comparison with unicode has failed. (`#1864`_) + Thanks `@AiOO`_ for the PR + * .. _@joguSD: https://github.com/joguSD +.. _@AiOO: https://github.com/AiOO .. _#1857: https://github.com/pytest-dev/pytest/issues/1857 +.. _#1864: https://github.com/pytest-dev/pytest/issues/1864 3.0.1 diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py index 040e4fc8d..9a6d32665 100644 --- a/_pytest/_code/code.py +++ b/_pytest/_code/code.py @@ -354,7 +354,7 @@ class ExceptionInfo(object): if exprinfo is None and isinstance(tup[1], AssertionError): exprinfo = getattr(tup[1], 'msg', None) if exprinfo is None: - exprinfo = str(tup[1]) + exprinfo = py._builtin._totext(tup[1]) if exprinfo and exprinfo.startswith('assert '): self._striptext = 'AssertionError: ' self._excinfo = tup diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 63d6ac98e..a3a29a76c 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -816,3 +816,12 @@ def test_assert_indirect_tuple_no_warning(testdir): result = testdir.runpytest('-rw') output = '\n'.join(result.stdout.lines) assert 'WR1' not in output + +def test_assert_with_unicode(monkeypatch, testdir): + testdir.makepyfile(u""" + # -*- coding: utf-8 -*- + def test_unicode(): + assert u'유니코드' == u'Unicode' + """) + result = testdir.runpytest() + result.stdout.fnmatch_lines(['*AssertionError*'])