Skip to content

Commit fbcf1a9

Browse files
authored
Merge pull request #3193 from pytest-dev/ref-docs
Reference docs
2 parents 1b53538 + 51c0256 commit fbcf1a9

35 files changed

+1378
-704
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
..
1+
..
22
You should *NOT* be adding new change log entries to this file, this
33
file is managed by towncrier. You *may* edit previous change logs to
44
fix problems like typo corrections or such.
@@ -377,7 +377,7 @@ Features
377377
- Match ``warns`` signature to ``raises`` by adding ``match`` keyword. (`#2708
378378
<https://github.com/pytest-dev/pytest/issues/2708>`_)
379379

380-
- Pytest now captures and displays output from the standard `logging` module.
380+
- Pytest now captures and displays output from the standard ``logging`` module.
381381
The user can control the logging level to be captured by specifying options
382382
in ``pytest.ini``, the command line and also during individual tests using
383383
markers. Also, a ``caplog`` fixture is available that enables users to test

_pytest/capture.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ def _ensure_only_one_capture_fixture(request, name):
197197

198198
@pytest.fixture
199199
def capsys(request):
200-
"""Enable capturing of writes to sys.stdout/sys.stderr and make
200+
"""Enable capturing of writes to ``sys.stdout`` and ``sys.stderr`` and make
201201
captured output available via ``capsys.readouterr()`` method calls
202-
which return a ``(out, err)`` tuple. ``out`` and ``err`` will be ``text``
202+
which return a ``(out, err)`` namedtuple. ``out`` and ``err`` will be ``text``
203203
objects.
204204
"""
205205
_ensure_only_one_capture_fixture(request, 'capsys')
@@ -209,7 +209,7 @@ def capsys(request):
209209

210210
@pytest.fixture
211211
def capsysbinary(request):
212-
"""Enable capturing of writes to sys.stdout/sys.stderr and make
212+
"""Enable capturing of writes to ``sys.stdout`` and ``sys.stderr`` and make
213213
captured output available via ``capsys.readouterr()`` method calls
214214
which return a ``(out, err)`` tuple. ``out`` and ``err`` will be ``bytes``
215215
objects.
@@ -225,7 +225,7 @@ def capsysbinary(request):
225225

226226
@pytest.fixture
227227
def capfd(request):
228-
"""Enable capturing of writes to file descriptors 1 and 2 and make
228+
"""Enable capturing of writes to file descriptors ``1`` and ``2`` and make
229229
captured output available via ``capfd.readouterr()`` method calls
230230
which return a ``(out, err)`` tuple. ``out`` and ``err`` will be ``text``
231231
objects.
@@ -272,6 +272,10 @@ def _install_capture_fixture_on_item(request, capture_class):
272272

273273

274274
class CaptureFixture(object):
275+
"""
276+
Object returned by :py:func:`capsys`, :py:func:`capsysbinary`, :py:func:`capfd` and :py:func:`capfdbinary`
277+
fixtures.
278+
"""
275279
def __init__(self, captureclass, request):
276280
self.captureclass = captureclass
277281
self.request = request
@@ -288,13 +292,18 @@ def close(self):
288292
cap.stop_capturing()
289293

290294
def readouterr(self):
295+
"""Read and return the captured output so far, resetting the internal buffer.
296+
297+
:return: captured content as a namedtuple with ``out`` and ``err`` string attributes
298+
"""
291299
try:
292300
return self._capture.readouterr()
293301
except AttributeError:
294302
return self._outerr
295303

296304
@contextlib.contextmanager
297305
def disabled(self):
306+
"""Temporarily disables capture while inside the 'with' block."""
298307
self._capture.suspend_capturing()
299308
capmanager = self.request.config.pluginmanager.getplugin('capturemanager')
300309
capmanager.suspend_global_capture(item=None, in_=False)

_pytest/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class PytestPluginManager(PluginManager):
169169
Overwrites :py:class:`pluggy.PluginManager <pluggy.PluginManager>` to add pytest-specific
170170
functionality:
171171
172-
* loading plugins from the command line, ``PYTEST_PLUGIN`` env variable and
172+
* loading plugins from the command line, ``PYTEST_PLUGINS`` env variable and
173173
``pytest_plugins`` global variables found in plugins being loaded;
174174
* ``conftest.py`` loading during start-up;
175175
"""

_pytest/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,6 @@ def getvalue(self):
379379
@pytest.fixture(scope='session')
380380
def doctest_namespace():
381381
"""
382-
Inject names into the doctest namespace.
382+
Fixture that returns a :py:class:`dict` that will be injected into the namespace of doctests.
383383
"""
384384
return dict()

_pytest/fixtures.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def __call__(self, function):
858858

859859

860860
def fixture(scope="function", params=None, autouse=False, ids=None, name=None):
861-
""" (return a) decorator to mark a fixture factory function.
861+
"""Decorator to mark a fixture factory function.
862862
863863
This decorator can be used (with or without parameters) to define a
864864
fixture function. The name of the fixture function can later be
@@ -923,7 +923,15 @@ def yield_fixture(scope="function", params=None, autouse=False, ids=None, name=N
923923

924924
@fixture(scope="session")
925925
def pytestconfig(request):
926-
""" the pytest config object with access to command line opts."""
926+
"""Session-scoped fixture that returns the :class:`_pytest.config.Config` object.
927+
928+
Example::
929+
930+
def test_foo(pytestconfig):
931+
if pytestconfig.getoption("verbose"):
932+
...
933+
934+
"""
927935
return request.config
928936

929937

_pytest/junitxml.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ def record_xml_property(request):
200200
"""Add extra xml properties to the tag for the calling test.
201201
The fixture is callable with ``(name, value)``, with value being automatically
202202
xml-encoded.
203+
204+
Example::
205+
206+
def test_function(record_xml_property):
207+
record_xml_property("example_key", 1)
203208
"""
204209
request.node.warn(
205210
code='C3',

_pytest/mark.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ class MarkerError(Exception):
116116

117117

118118
def param(*values, **kw):
119+
"""Specify a parameter in a `pytest.mark.parametrize`_ call.
120+
121+
.. code-block:: python
122+
123+
@pytest.mark.parametrize("test_input,expected", [
124+
("3+5", 8),
125+
pytest.param("6*9", 42, marks=pytest.mark.xfail),
126+
])
127+
def test_eval(test_input, expected):
128+
assert eval(test_input) == expected
129+
130+
:param values: variable args of the values of the parameter set, in order.
131+
:keyword marks: a single mark or a list of marks to be applied to this parameter set.
132+
:keyword str id: the id to attribute to this parameter set.
133+
"""
119134
return ParameterSet.param(*values, **kw)
120135

121136

_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def setall(self, funcargs, id, param):
717717

718718
class Metafunc(fixtures.FuncargnamesCompatAttr):
719719
"""
720-
Metafunc objects are passed to the ``pytest_generate_tests`` hook.
720+
Metafunc objects are passed to the :func:`pytest_generate_tests <_pytest.hookspec.pytest_generate_tests>` hook.
721721
They help to inspect a test function and to generate tests according to
722722
test configuration or values specified in the class or module where a
723723
test function is defined.

_pytest/python_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,9 @@ def raises(expected_exception, *args, **kwargs):
547547
The string will be evaluated using the same ``locals()`` and ``globals()``
548548
at the moment of the ``raises`` call.
549549
550-
.. autoclass:: _pytest._code.ExceptionInfo
551-
:members:
550+
.. currentmodule:: _pytest._code
551+
552+
Consult the API of ``excinfo`` objects: :class:`ExceptionInfo`.
552553
553554
.. note::
554555
Similar to caught exception objects in Python, explicitly clearing

_pytest/recwarn.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
@yield_fixture
1818
def recwarn():
19-
"""Return a WarningsRecorder instance that provides these methods:
20-
21-
* ``pop(category=None)``: return last warning matching the category.
22-
* ``clear()``: clear list of warnings
19+
"""Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.
2320
2421
See http://docs.python.org/library/warnings.html for information
2522
on warning categories.
@@ -88,11 +85,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
8885
def warns(expected_warning, *args, **kwargs):
8986
"""Assert that code raises a particular class of warning.
9087
91-
Specifically, the input @expected_warning can be a warning class or
92-
tuple of warning classes, and the code must return that warning
93-
(if a single class) or one of those warnings (if a tuple).
88+
Specifically, the parameter ``expected_warning`` can be a warning class or
89+
sequence of warning classes, and the inside the ``with`` block must issue a warning of that class or
90+
classes.
9491
95-
This helper produces a list of ``warnings.WarningMessage`` objects,
92+
This helper produces a list of :class:`warnings.WarningMessage` objects,
9693
one for each warning raised.
9794
9895
This function can be used as a context manager, or any of the other ways

_pytest/tmpdir.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def tmpdir(request, tmpdir_factory):
116116
created as a sub directory of the base temporary
117117
directory. The returned object is a `py.path.local`_
118118
path object.
119+
120+
.. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html
119121
"""
120122
name = request.node.name
121123
name = re.sub(r"[\W]", "_", name)

changelog/1713.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a `reference <https://docs.pytest.org/en/latest/reference.html>`_ page to the docs.

doc/en/_templates/globaltoc.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ <h3><a href="{{ pathto(master_doc) }}">{{ _('Table Of Contents') }}</a></h3>
22

33
<ul>
44
<li><a href="{{ pathto('index') }}">Home</a></li>
5-
<li><a href="{{ pathto('contents') }}">Contents</a></li>
65
<li><a href="{{ pathto('getting-started') }}">Install</a></li>
6+
<li><a href="{{ pathto('contents') }}">Contents</a></li>
7+
<li><a href="{{ pathto('reference') }}">Reference</a></li>
78
<li><a href="{{ pathto('example/index') }}">Examples</a></li>
89
<li><a href="{{ pathto('customize') }}">Customize</a></li>
9-
<li><a href="{{ pathto('contact') }}">Contact</a></li>
10-
<li><a href="{{ pathto('talks') }}">Talks/Posts</a></li>
1110
<li><a href="{{ pathto('changelog') }}">Changelog</a></li>
11+
<li><a href="{{ pathto('contributing') }}">Contributing</a></li>
1212
<li><a href="{{ pathto('backwards-compatibility') }}">Backwards Compatibility</a></li>
1313
<li><a href="{{ pathto('license') }}">License</a></li>
14+
<li><a href="{{ pathto('contact') }}">Contact Channels</a></li>
1415
</ul>
1516

1617
{%- if display_toc %}

doc/en/_templates/links.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<h3>Useful Links</h3>
22
<ul>
3-
<li><a href="{{ pathto('index') }}">The pytest Website</a></li>
4-
<li><a href="{{ pathto('contributing') }}">Contribution Guide</a></li>
53
<li><a href="https://pypi.python.org/pypi/pytest">pytest @ PyPI</a></li>
64
<li><a href="https://github.com/pytest-dev/pytest/">pytest @ GitHub</a></li>
75
<li><a href="http://plugincompat.herokuapp.com/">3rd party plugins</a></li>

0 commit comments

Comments
 (0)