Proof of concept
This commit is contained in:
parent
02ba39bfcd
commit
0dcb4b9fec
|
@ -704,7 +704,12 @@ class ExceptionInfo(Generic[E]):
|
||||||
If it matches `True` is returned, otherwise an `AssertionError` is raised.
|
If it matches `True` is returned, otherwise an `AssertionError` is raised.
|
||||||
"""
|
"""
|
||||||
__tracebackhide__ = True
|
__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}"
|
msg = f"Regex pattern did not match.\n Regex: {regexp!r}\n Input: {value!r}"
|
||||||
if regexp == value:
|
if regexp == value:
|
||||||
msg += "\n Did you mean to `re.escape()` the regex?"
|
msg += "\n Did you mean to `re.escape()` the regex?"
|
||||||
|
|
|
@ -1648,3 +1648,38 @@ def test_hidden_entries_of_chained_exceptions_are_not_shown(pytester: Pytester)
|
||||||
],
|
],
|
||||||
consecutive=True,
|
consecutive=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip("sys.version_info < (3,11)")
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"error,notes,match",
|
||||||
|
[
|
||||||
|
(Exception("test"), [], "test"),
|
||||||
|
(AssertionError("foo"), ["bar"], "bar"),
|
||||||
|
(AssertionError("foo"), ["bar", "baz"], "bar"),
|
||||||
|
(AssertionError("foo"), ["bar", "baz"], "baz"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_check_error_notes_success(error, notes, match):
|
||||||
|
for note in notes:
|
||||||
|
error.add_note(note)
|
||||||
|
|
||||||
|
with pytest.raises(Exception, match=match):
|
||||||
|
raise error
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip("sys.version_info < (3,11)")
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"error, notes, match",
|
||||||
|
[
|
||||||
|
(Exception("test"), [], "foo"),
|
||||||
|
(AssertionError("foo"), ["bar"], "baz"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_check_error_notes_failure(error, notes, match):
|
||||||
|
for note in notes:
|
||||||
|
error.add_note(note)
|
||||||
|
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
with pytest.raises(type(error), match=match):
|
||||||
|
raise error
|
||||||
|
|
Loading…
Reference in New Issue