MCPcopy
hub / github.com/pytest-dev/pytest / match

Method match

src/_pytest/_code/code.py:776–793  ·  view source on GitHub ↗

Check whether the regular expression `regexp` matches the string representation of the exception using :func:`python:re.search`. If it matches `True` is returned, otherwise an `AssertionError` is raised.

(self, regexp: str | re.Pattern[str])

Source from the content-addressed store, hash-verified

774 return fmt.repr_excinfo(self)
775
776 def match(self, regexp: str | re.Pattern[str]) -> Literal[True]:
777 """Check whether the regular expression `regexp` matches the string
778 representation of the exception using :func:`python:re.search`.
779
780 If it matches `True` is returned, otherwise an `AssertionError` is raised.
781 """
782 __tracebackhide__ = True
783 value = stringify_exception(self.value)
784 msg = (
785 f"Regex pattern did not match.\n"
786 f" Expected regex: {regexp!r}\n"
787 f" Actual message: {value!r}"
788 )
789 if regexp == value:
790 msg += "\n Did you mean to `re.escape()` the regex?"
791 assert re.search(regexp, value), msg
792 # Return True to allow for "assert excinfo.match()".
793 return True
794
795 def _group_contains(
796 self,

Callers 15

re_match_lines_randomMethod · 0.80
re_match_linesMethod · 0.80
no_re_match_lineMethod · 0.80
lexMethod · 0.80
iter_pluginsFunction · 0.80
find_next_versionFunction · 0.80
test_number_reMethod · 0.80
test_raises_matchMethod · 0.80

Calls 1

stringify_exceptionFunction · 0.85

Tested by 12

re_match_lines_randomMethod · 0.64
re_match_linesMethod · 0.64
no_re_match_lineMethod · 0.64
test_number_reMethod · 0.64
test_raises_matchMethod · 0.64
test_boolMethod · 0.64
test_tb_entry_strMethod · 0.64
test_match_succeedsFunction · 0.64