File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
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 context manager ``does_not_raise `` to serve
572
+ It is helpful to define a no-op context manager ``does_not_raise `` to serve
573
573
as a complement to ``raises ``. For example::
574
574
575
575
from contextlib import contextmanager
@@ -594,7 +594,15 @@ as a complement to ``raises``. For example::
594
594
In the example above, the first three test cases should run unexceptionally,
595
595
while the fourth should raise ``ZeroDivisionError ``.
596
596
597
- In Python 3.7+, you can simply use ``nullcontext `` to define
598
- ``does_not_raise ``::
597
+ If you're only supporting Python 3.7+, you can simply use ``nullcontext ``
598
+ to define ``does_not_raise ``::
599
599
600
600
from contextlib import nullcontext as does_not_raise
601
+
602
+ Or, if you're supporting Python 3.3+ you can use::
603
+
604
+ from contextlib import ExitStack as does_not_raise
605
+
606
+ Or, if desired, you can ``pip install contextlib2 `` and use::
607
+
608
+ from contextlib2 import ExitStack as does_not_raise
You can’t perform that action at this time.
0 commit comments