diff options
author | Omar Kohl <omarkohl@gmail.com> | 2016-04-02 17:24:08 +0200 |
---|---|---|
committer | Omar Kohl <omarkohl@gmail.com> | 2016-04-03 11:22:44 +0200 |
commit | c578226d43e96d1cc86f14de0779acd96222f0e4 (patch) | |
tree | 2ef8d5c17941b128dd9f999ad354597dc449de40 /doc/en/assert.rst | |
parent | fed89ef5491703c74cc287f63668756dbf3d15d2 (diff) | |
download | pytest-c578226d43e96d1cc86f14de0779acd96222f0e4.tar.gz |
Implement ExceptionInfo.match() to match regexp on str(exception)
This implements similar functionality to
unittest.TestCase.assertRegexpMatches()
closes #372
Diffstat (limited to 'doc/en/assert.rst')
-rw-r--r-- | doc/en/assert.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/en/assert.rst b/doc/en/assert.rst index e7f14e8bd..f095d6878 100644 --- a/doc/en/assert.rst +++ b/doc/en/assert.rst @@ -110,6 +110,24 @@ 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:: + + import pytest + + def myfunc(): + raise ValueError("Exception 123 raised") + + def test_match(): + with pytest.raises(ValueError) as excinfo: + 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 +well. + .. _`assertwarns`: |