Updated documentation
This commit is contained in:
parent
ca093673fb
commit
c29130d400
|
@ -66,7 +66,8 @@
|
||||||
* Add ``build/`` and ``dist/`` to the default ``--norecursedirs`` list. Thanks
|
* Add ``build/`` and ``dist/`` to the default ``--norecursedirs`` list. Thanks
|
||||||
`@mikofski`_ for the report and `@tomviner`_ for the PR (`#1544`_).
|
`@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`_).
|
Thanks `@palaviv`_ for the complete PR (`#1616`_).
|
||||||
|
|
||||||
.. _@milliams: https://github.com/milliams
|
.. _@milliams: https://github.com/milliams
|
||||||
|
|
|
@ -1337,6 +1337,14 @@ def raises(expected_exception, *args, **kwargs):
|
||||||
>>> with raises(ZeroDivisionError):
|
>>> with raises(ZeroDivisionError):
|
||||||
... 1/0
|
... 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::
|
.. note::
|
||||||
|
|
||||||
When using ``pytest.raises`` as a context manager, it's worthwhile to
|
When using ``pytest.raises`` as a context manager, it's worthwhile to
|
||||||
|
|
|
@ -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
|
the actual exception raised. The main attributes of interest are
|
||||||
``.type``, ``.value`` and ``.traceback``.
|
``.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,
|
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::
|
you may also use two other ways to test for an expected exception::
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue