Doc fix issue #11556
This commit is contained in:
parent
c1728948ac
commit
591176a57a
1
AUTHORS
1
AUTHORS
|
@ -422,5 +422,6 @@ Zac Hatfield-Dodds
|
||||||
Zachary Kneupper
|
Zachary Kneupper
|
||||||
Zachary OBrien
|
Zachary OBrien
|
||||||
Zhouxin Qiu
|
Zhouxin Qiu
|
||||||
|
Ziad Kermadi
|
||||||
Zoltán Máté
|
Zoltán Máté
|
||||||
Zsolt Cserna
|
Zsolt Cserna
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Remove/update recommendation about using nullcontext + parametrize in teh docs
|
|
@ -647,44 +647,3 @@ As the result:
|
||||||
- The test ``test_eval[1+7-8]`` passed, but the name is autogenerated and confusing.
|
- The test ``test_eval[1+7-8]`` passed, but the name is autogenerated and confusing.
|
||||||
- The test ``test_eval[basic_2+4]`` passed.
|
- The test ``test_eval[basic_2+4]`` passed.
|
||||||
- The test ``test_eval[basic_6*9]`` was expected to fail and did fail.
|
- The test ``test_eval[basic_6*9]`` was expected to fail and did fail.
|
||||||
|
|
||||||
.. _`parametrizing_conditional_raising`:
|
|
||||||
|
|
||||||
Parametrizing conditional raising
|
|
||||||
--------------------------------------------------------------------
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
``contextlib.nullcontext`` can be used to test cases that are not expected to
|
|
||||||
raise exceptions but that should result in some value. The value is given as the
|
|
||||||
``enter_result`` parameter, which will be available as the ``with`` statement’s
|
|
||||||
target (``e`` in the example below).
|
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from contextlib import nullcontext
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"example_input,expectation",
|
|
||||||
[
|
|
||||||
(3, nullcontext(2)),
|
|
||||||
(2, nullcontext(3)),
|
|
||||||
(1, nullcontext(6)),
|
|
||||||
(0, pytest.raises(ZeroDivisionError)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_division(example_input, expectation):
|
|
||||||
"""Test how much I know division."""
|
|
||||||
with expectation as e:
|
|
||||||
assert (6 / example_input) == e
|
|
||||||
|
|
||||||
In the example above, the first three test cases should run without any
|
|
||||||
exceptions, while the fourth should raise a``ZeroDivisionError`` exception,
|
|
||||||
which is expected by pytest.
|
|
||||||
|
|
Loading…
Reference in New Issue