Updated documentation

This commit is contained in:
palaviv 2016-06-19 23:34:42 +03:00
parent ca093673fb
commit c29130d400
3 changed files with 17 additions and 1 deletions

View File

@ -66,7 +66,8 @@
* Add ``build/`` and ``dist/`` to the default ``--norecursedirs`` list. Thanks
`@mikofski`_ for the report and `@tomviner`_ for the PR (`#1544`_).
* pytest.raises accepts a custom message to raise when no exception occurred.
* pytest.raises in the context manager form accepts a custom
message to raise when no exception occurred.
Thanks `@palaviv`_ for the complete PR (`#1616`_).
.. _@milliams: https://github.com/milliams

View File

@ -1337,6 +1337,14 @@ def raises(expected_exception, *args, **kwargs):
>>> with raises(ZeroDivisionError):
... 1/0
In the context manager form you may use the keyword argument
``message`` to specify a custom failure message::
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
... pass
... Failed: Expecting ZeroDivisionError
.. note::
When using ``pytest.raises`` as a context manager, it's worthwhile to

View File

@ -85,6 +85,13 @@ and if you need to have access to the actual exception info you may use::
the actual exception raised. The main attributes of interest are
``.type``, ``.value`` and ``.traceback``.
In the context manager form you may use the keyword argument
``message`` to specify a custom failure message::
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
... pass
... Failed: Expecting ZeroDivisionError
If you want to write test code that works on Python 2.4 as well,
you may also use two other ways to test for an expected exception::