From 10d0b8b8a10fc21dc3535e5368273ef6b4b67d5e Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 25 Jun 2019 12:40:07 +0100 Subject: [PATCH] use safe_str to serialize Exceptions Fixes #5478 --- src/_pytest/_code/code.py | 5 +++-- testing/python/raises.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 8c73ccc6adc..83403cd42f2 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -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 diff --git a/testing/python/raises.py b/testing/python/raises.py index cd463d74b07..db34c6624f5 100644 --- a/testing/python/raises.py +++ b/testing/python/raises.py @@ -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"