File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -569,7 +569,7 @@ Use :func:`pytest.raises` with the
569
569
:ref: `pytest.mark.parametrize ref ` decorator to write parametrized tests
570
570
in which some tests raise exceptions and others do not.
571
571
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
573
573
as a complement to ``raises ``. For example::
574
574
575
575
from contextlib import contextmanager
@@ -591,5 +591,10 @@ as a complement to ``raises``. For example::
591
591
with expectation:
592
592
assert (6 / example_input) is not None
593
593
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,
595
595
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
You can’t perform that action at this time.
0 commit comments