Skip to content

Commit 8a1afe4

Browse files
committed
Including note on using nullcontext in Python 3.7+
1 parent fd4289d commit 8a1afe4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

doc/en/example/parametrize.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ Use :func:`pytest.raises` with the
569569
:ref:`pytest.mark.parametrize ref` decorator to write parametrized tests
570570
in which some tests raise exceptions and others do not.
571571

572-
It is helpful to define a function such as ``does_not_raise`` to serve
572+
It is helpful to define a context manager ``does_not_raise`` to serve
573573
as a complement to ``raises``. For example::
574574

575575
from contextlib import contextmanager
@@ -591,5 +591,10 @@ as a complement to ``raises``. For example::
591591
with expectation:
592592
assert (6 / example_input) is not None
593593

594-
In this example, the first three test cases should run unexceptionally,
594+
In the example above, the first three test cases should run unexceptionally,
595595
while the fourth should raise ``ZeroDivisionError``.
596+
597+
In Python 3.7+, you can simply use ``nullcontext`` to define
598+
``does_not_raise``::
599+
600+
from contextlib import nullcontext as does_not_raise

0 commit comments

Comments
 (0)