Have pytest.raises match against exception __notes__ (#11227)

The doctest is skipped because add_note is only available in 3.11,

Closes #11223
This commit is contained in:
Isaac Virshup
2023-07-18 13:39:39 +02:00
committed by GitHub
parent 7c30f674c5
commit 1de0923e83
5 changed files with 71 additions and 8 deletions

View File

@@ -704,7 +704,12 @@ class ExceptionInfo(Generic[E]):
If it matches `True` is returned, otherwise an `AssertionError` is raised.
"""
__tracebackhide__ = True
value = str(self.value)
value = "\n".join(
[
str(self.value),
*getattr(self.value, "__notes__", []),
]
)
msg = f"Regex pattern did not match.\n Regex: {regexp!r}\n Input: {value!r}"
if regexp == value:
msg += "\n Did you mean to `re.escape()` the regex?"