Skip to content

Commit 09dee29

Browse files
committed
Use unicode message if regex is also unicode in ExceptionInfo.match
1 parent 86a4eb6 commit 09dee29

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/_pytest/_code/code.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,13 @@ def match(self, regexp):
572572
raised.
573573
"""
574574
__tracebackhide__ = True
575-
value = safe_str(self.value)
575+
value = (
576+
text_type(self.value) if isinstance(regexp, text_type) else str(self.value)
577+
)
576578
if not re.search(regexp, value):
577-
assert 0, "Pattern '{!s}' not found in '{!s}'".format(regexp, value)
579+
raise AssertionError(
580+
"Pattern '{!s}' not found in '{!s}'".format(regexp, value)
581+
)
578582
return True
579583

580584

testing/python/raises.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ def __class__(self):
279279
pass
280280
assert "via __class__" in excinfo.value.args[0]
281281

282-
def test_u(self):
282+
def test_unicode_message(self):
283+
"""pytest.raises should be able to match unicode messages when using a unicode regex (#5478)
284+
"""
283285
with pytest.raises(AssertionError, match=u"\u2603"):
284286
assert False, u"\u2603"

0 commit comments

Comments
 (0)