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:
@@ -843,6 +843,14 @@ def raises( # noqa: F811
|
||||
>>> with pytest.raises(ValueError, match=r'must be \d+$'):
|
||||
... raise ValueError("value must be 42")
|
||||
|
||||
The ``match`` argument searches the formatted exception string, which includes any
|
||||
`PEP-678 <https://peps.python.org/pep-0678/>` ``__notes__``:
|
||||
|
||||
>>> with pytest.raises(ValueError, match=r'had a note added'): # doctest: +SKIP
|
||||
... e = ValueError("value must be 42")
|
||||
... e.add_note("had a note added")
|
||||
... raise e
|
||||
|
||||
The context manager produces an :class:`ExceptionInfo` object which can be used to inspect the
|
||||
details of the captured exception::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user