diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index e621f3ee048..e99575e1176 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -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