Skip to content

Commit 2014534

Browse files
soxofaannicoddemus
authored andcommittedOct 10, 2024
Docs: improve/cleanup reference from/to recwarn (#12866)
Co-authored-by: Bruno Oliveira <[email protected]> (cherry picked from commit 26a29bd)
1 parent 40741c4 commit 2014534

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed
 

‎changelog/12866.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved cross-references concerning the :fixture:`recwarn` fixture.

‎doc/en/builtin.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
234234
recwarn -- .../_pytest/recwarn.py:35
235235
Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.
236236
237-
See https://docs.pytest.org/en/latest/how-to/capture-warnings.html for information
238-
on warning categories.
237+
See :ref:`warnings` for information on warning categories.
239238
240239
tmp_path_factory [session scope] -- .../_pytest/tmpdir.py:242
241240
Return a :class:`pytest.TempPathFactory` instance for the test session.

‎doc/en/how-to/capture-warnings.rst

+8-9
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ user code and third-party libraries, as recommended by :pep:`565`.
195195
This helps users keep their code modern and avoid breakages when deprecated warnings are effectively removed.
196196

197197
However, in the specific case where users capture any type of warnings in their test, either with
198-
:func:`pytest.warns`, :func:`pytest.deprecated_call` or using the :ref:`recwarn <recwarn>` fixture,
198+
:func:`pytest.warns`, :func:`pytest.deprecated_call` or using the :fixture:`recwarn` fixture,
199199
no warning will be displayed at all.
200200

201201
Sometimes it is useful to hide some specific deprecation warnings that happen in code that you have no control over
@@ -332,10 +332,10 @@ additional information:
332332
assert record[0].message.args[0] == "another warning"
333333
334334
Alternatively, you can examine raised warnings in detail using the
335-
:ref:`recwarn <recwarn>` fixture (see below).
335+
:fixture:`recwarn` fixture (see :ref:`below <recwarn>`).
336336

337337

338-
The :ref:`recwarn <recwarn>` fixture automatically ensures to reset the warnings
338+
The :fixture:`recwarn` fixture automatically ensures to reset the warnings
339339
filter at the end of the test, so no global state is leaked.
340340

341341
.. _`recording warnings`:
@@ -345,8 +345,8 @@ filter at the end of the test, so no global state is leaked.
345345
Recording warnings
346346
------------------
347347

348-
You can record raised warnings either using :func:`pytest.warns` or with
349-
the ``recwarn`` fixture.
348+
You can record raised warnings either using the :func:`pytest.warns` context manager or with
349+
the :fixture:`recwarn` fixture.
350350

351351
To record with :func:`pytest.warns` without asserting anything about the warnings,
352352
pass no arguments as the expected warning type and it will default to a generic Warning:
@@ -361,7 +361,7 @@ pass no arguments as the expected warning type and it will default to a generic
361361
assert str(record[0].message) == "user"
362362
assert str(record[1].message) == "runtime"
363363
364-
The ``recwarn`` fixture will record warnings for the whole function:
364+
The :fixture:`recwarn` fixture will record warnings for the whole function:
365365

366366
.. code-block:: python
367367
@@ -377,12 +377,11 @@ The ``recwarn`` fixture will record warnings for the whole function:
377377
assert w.filename
378378
assert w.lineno
379379
380-
Both ``recwarn`` and :func:`pytest.warns` return the same interface for recorded
381-
warnings: a WarningsRecorder instance. To view the recorded warnings, you can
380+
Both the :fixture:`recwarn` fixture and the :func:`pytest.warns` context manager return the same interface for recorded
381+
warnings: a :class:`~_pytest.recwarn.WarningsRecorder` instance. To view the recorded warnings, you can
382382
iterate over this instance, call ``len`` on it to get the number of recorded
383383
warnings, or index into it to get a particular recorded warning.
384384

385-
Full API: :class:`~_pytest.recwarn.WarningsRecorder`.
386385

387386
.. _`warns use cases`:
388387

‎doc/en/reference/reference.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,14 @@ record_testsuite_property
529529
recwarn
530530
~~~~~~~
531531

532-
**Tutorial**: :ref:`assertwarnings`
532+
**Tutorial**: :ref:`recwarn`
533533

534534
.. autofunction:: _pytest.recwarn.recwarn()
535535
:no-auto-options:
536536

537537
.. autoclass:: pytest.WarningsRecorder()
538538
:members:
539+
:special-members: __getitem__, __iter__, __len__
539540

540541

541542
.. fixture:: request

‎src/_pytest/recwarn.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
def recwarn() -> Generator[WarningsRecorder]:
3636
"""Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.
3737
38-
See https://docs.pytest.org/en/latest/how-to/capture-warnings.html for information
39-
on warning categories.
38+
See :ref:`warnings` for information on warning categories.
4039
"""
4140
wrec = WarningsRecorder(_ispytest=True)
4241
with wrec:

0 commit comments

Comments
 (0)