Skip to content

Commit

Permalink
Use unicode message if regex is also unicode in ExceptionInfo.match
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jun 30, 2019
1 parent 86a4eb6 commit 09dee29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/_pytest/_code/code.py
Expand Up @@ -572,9 +572,13 @@ def match(self, regexp):
raised.
"""
__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):
assert 0, "Pattern '{!s}' not found in '{!s}'".format(regexp, value)
raise AssertionError(
"Pattern '{!s}' not found in '{!s}'".format(regexp, value)
)
return True


Expand Down
4 changes: 3 additions & 1 deletion testing/python/raises.py
Expand Up @@ -279,6 +279,8 @@ def __class__(self):
pass
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"):
assert False, u"\u2603"

0 comments on commit 09dee29

Please sign in to comment.