Skip to content

Clarify docs for pytest.raises match. #5223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,13 @@ def raises(expected_exception, *args, **kwargs):
Assert that a code block/function call raises ``expected_exception``
or raise a failure exception otherwise.

:kwparam match: if specified, asserts that the exception matches a text or regex
:kwparam match: if specified, a string containing a regular expression,
or a regular expression object, that is tested against the string
representation of the exception using ``re.match``. To match a literal
string that may contain `special characters`__, the pattern can
first be escaped with ``re.escape``.

__ https://docs.python.org/3/library/re.html#regular-expression-syntax

:kwparam message: **(deprecated since 4.1)** if specified, provides a custom failure message
if the exception is not raised. See :ref:`the deprecation docs <raises message deprecated>` for a workaround.
Expand Down