Skip to content

Commit

Permalink
Merge pull request #2697 from nicoddemus/match-kw-version
Browse files Browse the repository at this point in the history
Update docs: ``match`` keyword was introduced in 3.1
  • Loading branch information
RonnyPfannschmidt committed Aug 17, 2017
2 parents 806d47b + f18780e commit 539523c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions _pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ def raises(expected_exception, *args, **kwargs):
...
>>> assert exc_info.type == ValueError
Or you can use the keyword argument ``match`` to assert that the
Since version ``3.1`` you can use the keyword argument ``match`` to assert that the
exception matches a text or regex::
>>> with raises(ValueError, match='must be 0 or None'):
Expand All @@ -502,7 +503,12 @@ def raises(expected_exception, *args, **kwargs):
>>> with raises(ValueError, match=r'must be \d+$'):
... raise ValueError("value must be 42")
Or you can specify a callable by passing a to-be-called lambda::
**Legacy forms**
The forms below are fully supported but are discouraged for new code because the
context manager form is regarded as more readable and less error-prone.
It is possible to specify a callable by passing a to-be-called lambda::
>>> raises(ZeroDivisionError, lambda: 1/0)
<ExceptionInfo ...>
Expand All @@ -516,11 +522,14 @@ def raises(expected_exception, *args, **kwargs):
>>> raises(ZeroDivisionError, f, x=0)
<ExceptionInfo ...>
A third possibility is to use a string to be executed::
It is also possible to pass a string to be evaluated at runtime::
>>> raises(ZeroDivisionError, "f(0)")
<ExceptionInfo ...>
The string will be evaluated using the same ``locals()`` and ``globals()``
at the moment of the ``raises`` call.
.. autoclass:: _pytest._code.ExceptionInfo
:members:
Expand Down

0 comments on commit 539523c

Please sign in to comment.