(self, e: BaseException)
| 476 | |
| 477 | class="cm"># TODO: harmonize with ExceptionInfo.match |
| 478 | def _check_match(self, e: BaseException) -> bool: |
| 479 | if self.match is None or re.search( |
| 480 | self.match, |
| 481 | stringified_exception := stringify_exception( |
| 482 | e, include_subexception_msg=False |
| 483 | ), |
| 484 | ): |
| 485 | return True |
| 486 | |
| 487 | class="cm"># if weclass="st">'re matching a group, make sure we're explicit to reduce confusion |
| 488 | class="cm"># if they're trying to match an exception contained within the group |
| 489 | maybe_specify_type = ( |
| 490 | fclass="st">" the `{_exception_type_name(type(e))}()`" |
| 491 | if isinstance(e, BaseExceptionGroup) |
| 492 | else class="st">"" |
| 493 | ) |
| 494 | if isinstance(self.rawmatch, str): |
| 495 | from _pytest.assertion.compare_text import _diff_text |
| 496 | from _pytest.assertion.highlight import dummy_highlighter |
| 497 | from _pytest.assertion.util import _config |
| 498 | from _pytest.config import Config |
| 499 | |
| 500 | verbose = ( |
| 501 | _config.get_verbosity(Config.VERBOSITY_ASSERTIONS) |
| 502 | if _config is not None |
| 503 | else 0 |
| 504 | ) |
| 505 | diff = list( |
| 506 | _diff_text( |
| 507 | self.rawmatch, stringified_exception, dummy_highlighter, verbose |
| 508 | ) |
| 509 | ) |
| 510 | self._fail_reason = (class="st">"\n" if diff[0][0] == class="st">"-" else class="st">"") + class="st">"\n".join(diff) |
| 511 | return False |
| 512 | |
| 513 | self._fail_reason = ( |
| 514 | fclass="st">"Regex pattern did not match{maybe_specify_type}.\n" |
| 515 | fclass="st">" Expected regex: {_match_pattern(self.match)!r}\n" |
| 516 | fclass="st">" Actual message: {stringified_exception!r}" |
| 517 | ) |
| 518 | if _match_pattern(self.match) == stringified_exception: |
| 519 | self._fail_reason += class="st">"\n Did you mean to `re.escape()` the regex?" |
| 520 | return False |
| 521 | |
| 522 | @abstractmethod |
| 523 | def matches( |
no test coverage detected