diff options
author | Joan Massich <sik@visor.udg.edu> | 2017-08-22 12:12:48 +0200 |
---|---|---|
committer | Joan Massich <sik@visor.udg.edu> | 2017-08-22 12:12:48 +0200 |
commit | 657976e98acc80a0eb44c519f25d89964dba8e10 (patch) | |
tree | 3497138381e81afc3958a85bca3532a99cd16937 /doc/en/assert.rst | |
parent | 539523cfee4c49a765569abcf68134b1255eedb5 (diff) | |
download | pytest-657976e98acc80a0eb44c519f25d89964dba8e10.tar.gz |
update raises documentation regarding regex match
Diffstat (limited to 'doc/en/assert.rst')
-rw-r--r-- | doc/en/assert.rst | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/doc/en/assert.rst b/doc/en/assert.rst index 406be7e9e..a8ddaecd8 100644 --- a/doc/en/assert.rst +++ b/doc/en/assert.rst @@ -119,9 +119,9 @@ 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 @@ -129,12 +129,11 @@ from ``unittest``) you can use the ``ExceptionInfo.match`` method:: 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. |