Skip to content

Commit 231e220

Browse files
committed
Move documentation contents from reference.rst to docstrings
It's better to have the documentation in one place, instead of having some in the docstring and some additional information added to the reference documentation in `reference.rst`.
1 parent 93fdb3e commit 231e220

File tree

4 files changed

+68
-67
lines changed

4 files changed

+68
-67
lines changed

doc/en/reference/reference.rst

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,6 @@ capsys
363363
.. autofunction:: _pytest.capture.capsys()
364364
:no-auto-options:
365365

366-
Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
367-
368-
Example:
369-
370-
.. code-block:: python
371-
372-
def test_output(capsys):
373-
print("hello")
374-
captured = capsys.readouterr()
375-
assert captured.out == "hello\n"
376-
377366
.. autoclass:: pytest.CaptureFixture()
378367
:members:
379368

@@ -388,18 +377,6 @@ capsysbinary
388377
.. autofunction:: _pytest.capture.capsysbinary()
389378
:no-auto-options:
390379

391-
Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.
392-
393-
Example:
394-
395-
.. code-block:: python
396-
397-
def test_output(capsysbinary):
398-
print("hello")
399-
captured = capsysbinary.readouterr()
400-
assert captured.out == b"hello\n"
401-
402-
403380
.. fixture:: capfd
404381

405382
capfd
@@ -410,18 +387,6 @@ capfd
410387
.. autofunction:: _pytest.capture.capfd()
411388
:no-auto-options:
412389

413-
Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
414-
415-
Example:
416-
417-
.. code-block:: python
418-
419-
def test_system_echo(capfd):
420-
os.system('echo "hello"')
421-
captured = capfd.readouterr()
422-
assert captured.out == "hello\n"
423-
424-
425390
.. fixture:: capfdbinary
426391

427392
capfdbinary
@@ -432,17 +397,6 @@ capfdbinary
432397
.. autofunction:: _pytest.capture.capfdbinary()
433398
:no-auto-options:
434399

435-
Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.
436-
437-
Example:
438-
439-
.. code-block:: python
440-
441-
def test_system_echo(capfdbinary):
442-
os.system('echo "hello"')
443-
captured = capfdbinary.readouterr()
444-
assert captured.out == b"hello\n"
445-
446400

447401
.. fixture:: doctest_namespace
448402

@@ -453,16 +407,6 @@ doctest_namespace
453407

454408
.. autofunction:: _pytest.doctest.doctest_namespace()
455409

456-
Usually this fixture is used in conjunction with another ``autouse`` fixture:
457-
458-
.. code-block:: python
459-
460-
@pytest.fixture(autouse=True)
461-
def add_np(doctest_namespace):
462-
doctest_namespace["np"] = numpy
463-
464-
For more details: :ref:`doctest_namespace`.
465-
466410

467411
.. fixture:: request
468412

@@ -600,12 +544,6 @@ recwarn
600544
.. autoclass:: pytest.WarningsRecorder()
601545
:members:
602546

603-
Each recorded warning is an instance of :class:`warnings.WarningMessage`.
604-
605-
.. note::
606-
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
607-
differently; see :ref:`ensuring_function_triggers`.
608-
609547

610548
.. fixture:: tmp_path
611549

src/_pytest/capture.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,22 @@ def disabled(self) -> Generator[None, None, None]:
876876

877877
@fixture
878878
def capsys(request: SubRequest) -> Generator[CaptureFixture[str], None, None]:
879-
"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
879+
r"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
880880
881881
The captured output is made available via ``capsys.readouterr()`` method
882882
calls, which return a ``(out, err)`` namedtuple.
883883
``out`` and ``err`` will be ``text`` objects.
884+
885+
Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
886+
887+
Example:
888+
889+
.. code-block:: python
890+
891+
def test_output(capsys):
892+
print("hello")
893+
captured = capsys.readouterr()
894+
assert captured.out == "hello\n"
884895
"""
885896
capman = request.config.pluginmanager.getplugin("capturemanager")
886897
capture_fixture = CaptureFixture[str](SysCapture, request, _ispytest=True)
@@ -893,11 +904,22 @@ def capsys(request: SubRequest) -> Generator[CaptureFixture[str], None, None]:
893904

894905
@fixture
895906
def capsysbinary(request: SubRequest) -> Generator[CaptureFixture[bytes], None, None]:
896-
"""Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.
907+
r"""Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.
897908
898909
The captured output is made available via ``capsysbinary.readouterr()``
899910
method calls, which return a ``(out, err)`` namedtuple.
900911
``out`` and ``err`` will be ``bytes`` objects.
912+
913+
Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.
914+
915+
Example:
916+
917+
.. code-block:: python
918+
919+
def test_output(capsysbinary):
920+
print("hello")
921+
captured = capsysbinary.readouterr()
922+
assert captured.out == b"hello\n"
901923
"""
902924
capman = request.config.pluginmanager.getplugin("capturemanager")
903925
capture_fixture = CaptureFixture[bytes](SysCaptureBinary, request, _ispytest=True)
@@ -910,11 +932,22 @@ def capsysbinary(request: SubRequest) -> Generator[CaptureFixture[bytes], None,
910932

911933
@fixture
912934
def capfd(request: SubRequest) -> Generator[CaptureFixture[str], None, None]:
913-
"""Enable text capturing of writes to file descriptors ``1`` and ``2``.
935+
r"""Enable text capturing of writes to file descriptors ``1`` and ``2``.
914936
915937
The captured output is made available via ``capfd.readouterr()`` method
916938
calls, which return a ``(out, err)`` namedtuple.
917939
``out`` and ``err`` will be ``text`` objects.
940+
941+
Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
942+
943+
Example:
944+
945+
.. code-block:: python
946+
947+
def test_system_echo(capfd):
948+
os.system('echo "hello"')
949+
captured = capfd.readouterr()
950+
assert captured.out == "hello\n"
918951
"""
919952
capman = request.config.pluginmanager.getplugin("capturemanager")
920953
capture_fixture = CaptureFixture[str](FDCapture, request, _ispytest=True)
@@ -927,11 +960,23 @@ def capfd(request: SubRequest) -> Generator[CaptureFixture[str], None, None]:
927960

928961
@fixture
929962
def capfdbinary(request: SubRequest) -> Generator[CaptureFixture[bytes], None, None]:
930-
"""Enable bytes capturing of writes to file descriptors ``1`` and ``2``.
963+
r"""Enable bytes capturing of writes to file descriptors ``1`` and ``2``.
931964
932965
The captured output is made available via ``capfd.readouterr()`` method
933966
calls, which return a ``(out, err)`` namedtuple.
934967
``out`` and ``err`` will be ``byte`` objects.
968+
969+
Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.
970+
971+
Example:
972+
973+
.. code-block:: python
974+
975+
def test_system_echo(capfdbinary):
976+
os.system('echo "hello"')
977+
captured = capfdbinary.readouterr()
978+
assert captured.out == b"hello\n"
979+
935980
"""
936981
capman = request.config.pluginmanager.getplugin("capturemanager")
937982
capture_fixture = CaptureFixture[bytes](FDCaptureBinary, request, _ispytest=True)

src/_pytest/doctest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,5 +730,16 @@ def _get_report_choice(key: str) -> int:
730730
@pytest.fixture(scope="session")
731731
def doctest_namespace() -> Dict[str, Any]:
732732
"""Fixture that returns a :py:class:`dict` that will be injected into the
733-
namespace of doctests."""
733+
namespace of doctests.
734+
735+
Usually this fixture is used in conjunction with another ``autouse`` fixture:
736+
737+
.. code-block:: python
738+
739+
@pytest.fixture(autouse=True)
740+
def add_np(doctest_namespace):
741+
doctest_namespace["np"] = numpy
742+
743+
For more details: :ref:`doctest_namespace`.
744+
"""
734745
return dict()

src/_pytest/recwarn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ def warns(
160160
class WarningsRecorder(warnings.catch_warnings):
161161
"""A context manager to record raised warnings.
162162
163+
Each recorded warning is an instance of :class:`warnings.WarningMessage`.
164+
163165
Adapted from `warnings.catch_warnings`.
166+
167+
.. note::
168+
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
169+
differently; see :ref:`ensuring_function_triggers`.
170+
164171
"""
165172

166173
def __init__(self, *, _ispytest: bool = False) -> None:

0 commit comments

Comments
 (0)