Skip to content

Commit 6d259c4

Browse files
authored
Merge pull request #5223 from 5uper5hoot/patch-1
Clarify docs for pytest.raises `match`.
2 parents dcf65a9 + d368636 commit 6d259c4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/_pytest/python_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,13 @@ def raises(expected_exception, *args, **kwargs):
558558
Assert that a code block/function call raises ``expected_exception``
559559
or raise a failure exception otherwise.
560560
561-
:kwparam match: if specified, asserts that the exception matches a text or regex
561+
:kwparam match: if specified, a string containing a regular expression,
562+
or a regular expression object, that is tested against the string
563+
representation of the exception using ``re.match``. To match a literal
564+
string that may contain `special characters`__, the pattern can
565+
first be escaped with ``re.escape``.
566+
567+
__ https://docs.python.org/3/library/re.html#regular-expression-syntax
562568
563569
:kwparam message: **(deprecated since 4.1)** if specified, provides a custom failure message
564570
if the exception is not raised. See :ref:`the deprecation docs <raises message deprecated>` for a workaround.

0 commit comments

Comments
 (0)