Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
palaviv committed Jun 19, 2016
1 parent ca09367 commit c29130d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions doc/en/assert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down

0 comments on commit c29130d

Please sign in to comment.