From 591176a57a5675b2d1231eceeacefe727000dc16 Mon Sep 17 00:00:00 2001 From: Ziad Kermadi Date: Thu, 26 Oct 2023 16:30:25 +0200 Subject: [PATCH] Doc fix issue #11556 --- AUTHORS | 1 + changelog/11556.doc.rst | 1 + doc/en/example/parametrize.rst | 41 ---------------------------------- 3 files changed, 2 insertions(+), 41 deletions(-) create mode 100644 changelog/11556.doc.rst diff --git a/AUTHORS b/AUTHORS index 5ccff644c..e11d1084d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -422,5 +422,6 @@ Zac Hatfield-Dodds Zachary Kneupper Zachary OBrien Zhouxin Qiu +Ziad Kermadi Zoltán Máté Zsolt Cserna diff --git a/changelog/11556.doc.rst b/changelog/11556.doc.rst new file mode 100644 index 000000000..54ee9e5ea --- /dev/null +++ b/changelog/11556.doc.rst @@ -0,0 +1 @@ +Remove/update recommendation about using nullcontext + parametrize in teh docs diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 4ea6f6e65..f0aed561d 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -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[basic_2+4]`` passed. - 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.