Skip to content

Commit

Permalink
use safe_str to serialize Exceptions Fixes #5478
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Jun 25, 2019
1 parent 4b104ba commit 10d0b8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/_pytest/_code/code.py
Expand Up @@ -572,8 +572,9 @@ def match(self, regexp):
raised.
"""
__tracebackhide__ = True
if not re.search(regexp, str(self.value)):
assert 0, "Pattern '{!s}' not found in '{!s}'".format(regexp, self.value)
value = safe_str(self.value)
if not re.search(regexp, value):
assert 0, "Pattern {!r} not found in {!r}".format(regexp, value)
return True


Expand Down
4 changes: 4 additions & 0 deletions testing/python/raises.py
Expand Up @@ -278,3 +278,7 @@ def __class__(self):
with pytest.raises(CrappyClass()):
pass
assert "via __class__" in excinfo.value.args[0]

def test_u(self):
with pytest.raises(AssertionError, match=u"\u2603"):
assert False, u"\u2603"

0 comments on commit 10d0b8b

Please sign in to comment.