use safe_str to serialize Exceptions Fixes #5478

This commit is contained in:
Thomas Grainger 2019-06-25 12:40:07 +01:00
parent 554bff8cc1
commit 013d0e66c7
No known key found for this signature in database
GPG Key ID: E452A1247BAC1A88
3 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1 @@
Use safe_str to serialize Exceptions in pytest.raises

View File

@ -572,8 +572,9 @@ class ExceptionInfo(object):
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 '{!s}' not found in '{!s}'".format(regexp, value)
return True

View File

@ -278,3 +278,7 @@ class TestRaises(object):
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"