From 6e510636c129a63645a165ba0917b550d721a1e9 Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Mon, 17 Jul 2023 20:06:27 +0200 Subject: [PATCH] Docs --- src/_pytest/python_api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 200b2b3aa..ac0ec5e5e 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -843,6 +843,13 @@ 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 ``__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::