Skip to content

Commit

Permalink
Merge pull request #2710 from massich/raises_match_doc
Browse files Browse the repository at this point in the history
[DOC] update raises documentation regarding regex match
  • Loading branch information
nicoddemus authored Aug 30, 2017
2 parents 539523c + 657976e commit 0824076
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions doc/en/assert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,21 @@ exceptions your own code is deliberately raising, whereas using
like documenting unfixed bugs (where the test describes what "should" happen)
or bugs in dependencies.

If you want to test that a regular expression matches on the string
representation of an exception (like the ``TestCase.assertRaisesRegexp`` method
from ``unittest``) you can use the ``ExceptionInfo.match`` method::
Also, the context manager form accepts a ``match`` keyword parameter to test
that a regular expression matches on the string representation of an exception
(like the ``TestCase.assertRaisesRegexp`` method from ``unittest``)::

import pytest

def myfunc():
raise ValueError("Exception 123 raised")

def test_match():
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match=r'.* 123 .*'):
myfunc()
excinfo.match(r'.* 123 .*')

The regexp parameter of the ``match`` method is matched with the ``re.search``
function. So in the above example ``excinfo.match('123')`` would have worked as
function. So in the above example ``match='123'`` would have worked as
well.


Expand Down

0 comments on commit 0824076

Please sign in to comment.