Skip to content

Commit 539523c

Browse files
Merge pull request #2697 from nicoddemus/match-kw-version
Update docs: ``match`` keyword was introduced in 3.1
2 parents 806d47b + f18780e commit 539523c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

_pytest/python_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ def raises(expected_exception, *args, **kwargs):
493493
...
494494
>>> assert exc_info.type == ValueError
495495
496-
Or you can use the keyword argument ``match`` to assert that the
496+
497+
Since version ``3.1`` you can use the keyword argument ``match`` to assert that the
497498
exception matches a text or regex::
498499
499500
>>> with raises(ValueError, match='must be 0 or None'):
@@ -502,7 +503,12 @@ def raises(expected_exception, *args, **kwargs):
502503
>>> with raises(ValueError, match=r'must be \d+$'):
503504
... raise ValueError("value must be 42")
504505
505-
Or you can specify a callable by passing a to-be-called lambda::
506+
**Legacy forms**
507+
508+
The forms below are fully supported but are discouraged for new code because the
509+
context manager form is regarded as more readable and less error-prone.
510+
511+
It is possible to specify a callable by passing a to-be-called lambda::
506512
507513
>>> raises(ZeroDivisionError, lambda: 1/0)
508514
<ExceptionInfo ...>
@@ -516,11 +522,14 @@ def raises(expected_exception, *args, **kwargs):
516522
>>> raises(ZeroDivisionError, f, x=0)
517523
<ExceptionInfo ...>
518524
519-
A third possibility is to use a string to be executed::
525+
It is also possible to pass a string to be evaluated at runtime::
520526
521527
>>> raises(ZeroDivisionError, "f(0)")
522528
<ExceptionInfo ...>
523529
530+
The string will be evaluated using the same ``locals()`` and ``globals()``
531+
at the moment of the ``raises`` call.
532+
524533
.. autoclass:: _pytest._code.ExceptionInfo
525534
:members:
526535

0 commit comments

Comments
 (0)