Adding does_not_raise to documentation only
This commit is contained in:
@@ -565,16 +565,25 @@ As the result:
|
||||
Parametrizing conditional raising
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Use :func:`pytest.raises` and :func:`pytest.does_not_raise` together with the
|
||||
:ref:`pytest.mark.parametrize ref` decorator to write parametrized tests in which some
|
||||
tests raise exceptions and others do not. For example::
|
||||
Use :func:`pytest.raises` with the
|
||||
:ref:`pytest.mark.parametrize ref` decorator to write parametrized tests
|
||||
in which some tests raise exceptions and others do not.
|
||||
|
||||
It is helpful to define a function such as ``does_not_raise`` to serve
|
||||
as a complement to ``raises``. For example::
|
||||
|
||||
from contextlib import contextmanager
|
||||
import pytest
|
||||
|
||||
@contextmanager
|
||||
def does_not_raise():
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.parametrize('example_input,expectation', [
|
||||
(3, pytest.does_not_raise()),
|
||||
(2, pytest.does_not_raise()),
|
||||
(1, pytest.does_not_raise()),
|
||||
(3, does_not_raise()),
|
||||
(2, does_not_raise()),
|
||||
(1, does_not_raise()),
|
||||
(0, pytest.raises(ZeroDivisionError)),
|
||||
])
|
||||
def test_division(example_input, expectation):
|
||||
|
||||
@@ -61,12 +61,6 @@ pytest.raises
|
||||
.. autofunction:: pytest.raises(expected_exception: Exception, [match], [message])
|
||||
:with: excinfo
|
||||
|
||||
pytest.does_not_raise
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. autofunction:: pytest.does_not_raise()
|
||||
:with: excinfo
|
||||
|
||||
pytest.deprecated_call
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user