Skip to content

Commit c29130d

Browse files
committed
Updated documentation
1 parent ca09367 commit c29130d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
* Add ``build/`` and ``dist/`` to the default ``--norecursedirs`` list. Thanks
6767
`@mikofski`_ for the report and `@tomviner`_ for the PR (`#1544`_).
6868

69-
* pytest.raises accepts a custom message to raise when no exception occurred.
69+
* pytest.raises in the context manager form accepts a custom
70+
message to raise when no exception occurred.
7071
Thanks `@palaviv`_ for the complete PR (`#1616`_).
7172

7273
.. _@milliams: https://github.com/milliams

_pytest/python.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,14 @@ def raises(expected_exception, *args, **kwargs):
13371337
>>> with raises(ZeroDivisionError):
13381338
... 1/0
13391339
1340+
In the context manager form you may use the keyword argument
1341+
``message`` to specify a custom failure message::
1342+
1343+
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
1344+
... pass
1345+
... Failed: Expecting ZeroDivisionError
1346+
1347+
13401348
.. note::
13411349
13421350
When using ``pytest.raises`` as a context manager, it's worthwhile to

doc/en/assert.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ and if you need to have access to the actual exception info you may use::
8585
the actual exception raised. The main attributes of interest are
8686
``.type``, ``.value`` and ``.traceback``.
8787

88+
In the context manager form you may use the keyword argument
89+
``message`` to specify a custom failure message::
90+
91+
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
92+
... pass
93+
... Failed: Expecting ZeroDivisionError
94+
8895
If you want to write test code that works on Python 2.4 as well,
8996
you may also use two other ways to test for an expected exception::
9097

0 commit comments

Comments
 (0)