Use unicode message if regex is also unicode in ExceptionInfo.match
This commit is contained in:
parent
86a4eb6008
commit
09dee292ca
|
@ -572,9 +572,13 @@ class ExceptionInfo(object):
|
||||||
raised.
|
raised.
|
||||||
"""
|
"""
|
||||||
__tracebackhide__ = True
|
__tracebackhide__ = True
|
||||||
value = safe_str(self.value)
|
value = (
|
||||||
|
text_type(self.value) if isinstance(regexp, text_type) else str(self.value)
|
||||||
|
)
|
||||||
if not re.search(regexp, value):
|
if not re.search(regexp, value):
|
||||||
assert 0, "Pattern '{!s}' not found in '{!s}'".format(regexp, value)
|
raise AssertionError(
|
||||||
|
"Pattern '{!s}' not found in '{!s}'".format(regexp, value)
|
||||||
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,8 @@ class TestRaises(object):
|
||||||
pass
|
pass
|
||||||
assert "via __class__" in excinfo.value.args[0]
|
assert "via __class__" in excinfo.value.args[0]
|
||||||
|
|
||||||
def test_u(self):
|
def test_unicode_message(self):
|
||||||
|
"""pytest.raises should be able to match unicode messages when using a unicode regex (#5478)
|
||||||
|
"""
|
||||||
with pytest.raises(AssertionError, match=u"\u2603"):
|
with pytest.raises(AssertionError, match=u"\u2603"):
|
||||||
assert False, u"\u2603"
|
assert False, u"\u2603"
|
||||||
|
|
Loading…
Reference in New Issue