Adding does_not_raise to documentation only

This commit is contained in:
Arel Cordero
2019-01-27 16:10:11 +00:00
parent 977adf1354
commit fd4289dae0
6 changed files with 29 additions and 54 deletions
+15 -6
View File
@@ -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):
-6
View File
@@ -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
~~~~~~~~~~~~~~~~~~~~~~