Fix references for warnings use cases

This commit is contained in:
Olga Matoula 2022-01-13 18:06:03 +00:00
parent e69f04e3ce
commit 51ea042162
4 changed files with 32 additions and 29 deletions

View File

@ -225,7 +225,7 @@ Using ``pytest.warns(None)``
Its correct usage was checking that the code emits at least one warning of any type - like ``pytest.warns()``
or ``pytest.warns(Warning)``.
See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for use cases.
See :ref:`warns-use-cases` for examples.
The ``--strict`` command-line option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -300,32 +300,6 @@ filter at the end of the test, so no global state is leaked.
.. _recwarn:
Additional use cases of warnings in tests
-----------------------------------------
Here are some use cases involving warnings that often come up in tests, and suggestions on how to deal with them:
- To ensure that **any** warning is emitted, use:
.. code-block:: python
with pytest.warns():
pass
- To ensure that **no** warnings are emitted, use:
.. code-block:: python
with warnings.catch_warnings():
warnings.simplefilter("error")
- To suppress warnings, use:
.. code-block:: python
with warnings.catch_warnings():
warnings.simplefilter("ignore")
Recording warnings
------------------
@ -370,6 +344,35 @@ warnings, or index into it to get a particular recorded warning.
Full API: :class:`~_pytest.recwarn.WarningsRecorder`.
.. _`warns use cases`:
Additional use cases of warnings in tests
-----------------------------------------
Here are some use cases involving warnings that often come up in tests, and suggestions on how to deal with them:
- To ensure that **any** warning is emitted, use:
.. code-block:: python
with pytest.warns():
pass
- To ensure that **no** warnings are emitted, use:
.. code-block:: python
with warnings.catch_warnings():
warnings.simplefilter("error")
- To suppress warnings, use:
.. code-block:: python
with warnings.catch_warnings():
warnings.simplefilter("ignore")
.. _custom_failure_messages:
Custom failure messages

View File

@ -91,7 +91,7 @@ WARNS_NONE_ARG = PytestRemovedIn8Warning(
"Passing None has been deprecated.\n"
"See https://docs.pytest.org/en/latest/how-to/capture-warnings.html"
"#additional-use-cases-of-warnings-in-tests"
" for alternativesin common use cases."
" for alternatives in common use cases."
)
KEYWORD_MSG_ARG = UnformattedWarning(

View File

@ -141,7 +141,7 @@ def test_warns_none_is_deprecated():
"Passing None has been deprecated.\n"
"See https://docs.pytest.org/en/latest/how-to/capture-warnings.html"
"#additional-use-cases-of-warnings-in-tests"
" for alternativesin common use cases."
" for alternatives in common use cases."
),
):
with pytest.warns(None): # type: ignore[call-overload]