Skip to content

Commit 922b603

Browse files
Add CLI options reference documentation (#13930)
Co-authored-by: Ran Benita <[email protected]>
1 parent 3e75c0a commit 922b603

31 files changed

+675
-105
lines changed

changelog/4492.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The API Reference now contains cross-reference-able documentation of :ref:`pytest's command-line flags <command-line-flags>`.

doc/en/backwards-compatibility.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Keeping backwards compatibility has a very high priority in the pytest project.
6060

6161
With the pytest 3.0 release, we introduced a clear communication scheme for when we will actually remove the old busted joint and politely ask you to use the new hotness instead, while giving you enough time to adjust your tests or raise concerns if there are valid reasons to keep deprecated functionality around.
6262

63-
To communicate changes, we issue deprecation warnings using a custom warning hierarchy (see :ref:`internal-warnings`). These warnings may be suppressed using the standard means: ``-W`` command-line flag or ``filterwarnings`` ini options (see :ref:`warnings`), but we suggest to use these sparingly and temporarily, and heed the warnings when possible.
63+
To communicate changes, we issue deprecation warnings using a custom warning hierarchy (see :ref:`internal-warnings`). These warnings may be suppressed using the standard means: :option:`-W` command-line flag or :confval:`filterwarnings` configuration option (see :ref:`warnings`), but we suggest to use these sparingly and temporarily, and heed the warnings when possible.
6464

6565
We will only start the removal of deprecated functionality in major releases (e.g. if we deprecate something in 3.0, we will start to remove it in 4.0), and keep it around for at least two minor releases (e.g. if we deprecate something in 3.9 and 4.0 is the next release, we start to remove it in 5.0, not in 4.0).
6666

doc/en/builtin.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For information on plugin hooks and objects, see :ref:`plugins`.
1212

1313
For information on the ``pytest.mark`` mechanism, see :ref:`mark`.
1414

15-
For information about fixtures, see :ref:`fixtures`. To see a complete list of available fixtures (add ``-v`` to also see fixtures with leading ``_``), type :
15+
For information about fixtures, see :ref:`fixtures`. To see a complete list of available fixtures (add :option:`-v` to also see fixtures with leading ``_``), type :
1616

1717
.. code-block:: pytest
1818
@@ -53,15 +53,15 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
5353
5454
capteesys -- .../_pytest/capture.py:1028
5555
Enable simultaneous text capturing and pass-through of writes
56-
to ``sys.stdout`` and ``sys.stderr`` as defined by ``--capture=``.
56+
to ``sys.stdout`` and ``sys.stderr`` as defined by :option:`--capture`.
5757
5858
5959
The captured output is made available via ``capteesys.readouterr()`` method
6060
calls, which return a ``(out, err)`` namedtuple.
6161
``out`` and ``err`` will be ``text`` objects.
6262
6363
The output is also passed-through, allowing it to be "live-printed",
64-
reported, or both as defined by ``--capture=``.
64+
reported, or both as defined by :option:`--capture`.
6565
6666
Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.
6767

doc/en/example/markers.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ Using ``-k expr`` to select tests based on their name
167167

168168
.. versionadded:: 2.0/2.3.4
169169

170-
You can use the ``-k`` command line option to specify an expression
170+
You can use the :option:`-k` command line option to specify an expression
171171
which implements a substring match on the test names instead of the
172-
exact match on markers that ``-m`` provides. This makes it easy to
172+
exact match on markers that :option:`-m` provides. This makes it easy to
173173
select tests based on their names:
174174

175175
.. versionchanged:: 5.4
@@ -225,7 +225,7 @@ Or to select "http" and "quick" tests:
225225
You can use ``and``, ``or``, ``not`` and parentheses.
226226

227227

228-
In addition to the test's name, ``-k`` also matches the names of the test's parents (usually, the name of the file and class it's in),
228+
In addition to the test's name, :option:`-k` also matches the names of the test's parents (usually, the name of the file and class it's in),
229229
attributes set on the test function, markers applied to it or its parents and any :attr:`extra keywords <_pytest.nodes.Node.extra_keyword_matches>`
230230
explicitly added to it or its parents.
231231

@@ -440,7 +440,7 @@ and here is one that specifies exactly the environment needed:
440440
441441
============================ 1 passed in 0.12s =============================
442442
443-
The ``--markers`` option always gives you a list of available markers:
443+
The :option:`--markers` option always gives you a list of available markers:
444444

445445
.. code-block:: pytest
446446
@@ -658,7 +658,7 @@ Automatically adding markers based on test names
658658
659659
If you have a test suite where test function names indicate a certain
660660
type of test, you can implement a hook that automatically defines
661-
markers so that you can use the ``-m`` option with it. Let's look
661+
markers so that you can use the :option:`-m` option with it. Let's look
662662
at this test module:
663663

664664
.. code-block:: python

doc/en/example/parametrize.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ Different options for test IDs
8383
------------------------------------
8484

8585
pytest will build a string that is the test ID for each set of values in a
86-
parametrized test. These IDs can be used with ``-k`` to select specific cases
86+
parametrized test. These IDs can be used with :option:`-k` to select specific cases
8787
to run, and they will also identify the specific case when one is failing.
88-
Running pytest with ``--collect-only`` will show the generated IDs.
88+
Running pytest with :option:`--collect-only` will show the generated IDs.
8989

9090
Numbers, strings, booleans and None will have their usual string representation
9191
used in the test ID. For other objects, pytest will make a string based on

doc/en/example/pythoncollection.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Ignore paths during test collection
55
-----------------------------------
66

77
You can easily ignore certain test directories and modules during collection
8-
by passing the ``--ignore=path`` option on the cli. ``pytest`` allows multiple
8+
by passing the :option:`--ignore=path` option on the cli. ``pytest`` allows multiple
99
``--ignore`` options. Example:
1010

1111
.. code-block:: text
@@ -43,16 +43,16 @@ you will see that ``pytest`` only collects test-modules, which do not match the
4343
4444
========================= 5 passed in 0.02 seconds =========================
4545
46-
The ``--ignore-glob`` option allows to ignore test file paths based on Unix shell-style wildcards.
47-
If you want to exclude test-modules that end with ``_01.py``, execute ``pytest`` with ``--ignore-glob='*_01.py'``.
46+
The :option:`--ignore-glob` option allows to ignore test file paths based on Unix shell-style wildcards.
47+
If you want to exclude test-modules that end with ``_01.py``, execute ``pytest`` with :option:`--ignore-glob='*_01.py'`.
4848

4949
Deselect tests during test collection
5050
-------------------------------------
5151

52-
Tests can individually be deselected during collection by passing the ``--deselect=item`` option.
52+
Tests can individually be deselected during collection by passing the :option:`--deselect=item` option.
5353
For example, say ``tests/foobar/test_foobar_01.py`` contains ``test_a`` and ``test_b``.
5454
You can run all of the tests within ``tests/`` *except* for ``tests/foobar/test_foobar_01.py::test_a``
55-
by invoking ``pytest`` with ``--deselect tests/foobar/test_foobar_01.py::test_a``.
55+
by invoking ``pytest`` with ``--deselect=tests/foobar/test_foobar_01.py::test_a``.
5656
``pytest`` allows multiple ``--deselect`` options.
5757

5858
.. _duplicate-paths:
@@ -73,7 +73,7 @@ Example:
7373
7474
Just collect tests once.
7575

76-
To collect duplicate tests, use the ``--keep-duplicates`` option on the cli.
76+
To collect duplicate tests, use the :option:`--keep-duplicates` option on the cli.
7777
Example:
7878

7979
.. code-block:: pytest
@@ -168,7 +168,7 @@ You can check for multiple glob patterns by adding a space between the patterns:
168168
Interpreting cmdline arguments as Python packages
169169
-----------------------------------------------------
170170

171-
You can use the ``--pyargs`` option to make ``pytest`` try
171+
You can use the :option:`--pyargs` option to make ``pytest`` try
172172
interpreting arguments as python package names, deriving
173173
their file system path and then running the test. For
174174
example if you have unittest2 installed you can type:

doc/en/example/simple.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The actual command line executed is:
4343
pytest -ra -q -v -m slow
4444
4545
Note that as usual for other command-line applications, in case of conflicting options the last one wins, so the example
46-
above will show verbose output because ``-v`` overwrites ``-q``.
46+
above will show verbose output because :option:`-v` overwrites :option:`-q`.
4747

4848

4949
.. _request example:
@@ -353,7 +353,7 @@ Example:
353353
354354
The ``__tracebackhide__`` setting influences ``pytest`` showing
355355
of tracebacks: the ``checkconfig`` function will not be shown
356-
unless the ``--full-trace`` command line option is specified.
356+
unless the :option:`--full-trace` command line option is specified.
357357
Let's run our little function:
358358

359359
.. code-block:: pytest
@@ -998,7 +998,7 @@ information.
998998

999999

10001000
Sometimes a test session might get stuck and there might be no easy way to figure out
1001-
which test got stuck, for example if pytest was run in quiet mode (``-q``) or you don't have access to the console
1001+
which test got stuck, for example if pytest was run in quiet mode (:option:`-q`) or you don't have access to the console
10021002
output. This is particularly a problem if the problem happens only sporadically, the famous "flaky" kind of tests.
10031003

10041004
``pytest`` sets the :envvar:`PYTEST_CURRENT_TEST` environment variable when running tests, which can be inspected

doc/en/explanation/goodpractices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ want to distribute them along with your application:
170170
test_view.py
171171
...
172172
173-
In this scheme, it is easy to run your tests using the ``--pyargs`` option:
173+
In this scheme, it is easy to run your tests using the :option:`--pyargs` option:
174174

175175
.. code-block:: bash
176176
@@ -217,7 +217,7 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
217217
from each other and thus deriving a canonical import name helps
218218
to avoid surprises such as a test module getting imported twice.
219219

220-
With ``--import-mode=importlib`` things are less convoluted because
220+
With :option:`--import-mode=importlib` things are less convoluted because
221221
pytest doesn't need to change ``sys.path``, making things much less
222222
surprising.
223223

doc/en/explanation/pythonpath.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Import modes
1111
pytest as a testing framework needs to import test modules and ``conftest.py`` files for execution.
1212

1313
Importing files in Python is a non-trivial process, so aspects of the
14-
import process can be controlled through the ``--import-mode`` command-line flag, which can assume
14+
import process can be controlled through the :option:`--import-mode` command-line flag, which can assume
1515
these values:
1616

1717
.. _`import-mode-prepend`:
@@ -44,7 +44,7 @@ these values:
4444
pkg_under_test/
4545

4646
the tests will run against the installed version
47-
of ``pkg_under_test`` when ``--import-mode=append`` is used whereas
47+
of ``pkg_under_test`` when :option:`--import-mode=append` is used whereas
4848
with ``prepend``, they would pick up the local version. This kind of confusion is why
4949
we advocate for using :ref:`src-layouts <src-layout>`.
5050

doc/en/getting-started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Find out what kind of builtin :ref:`pytest fixtures <fixtures>` exist with the c
262262
263263
pytest --fixtures # shows builtin and custom fixtures
264264
265-
Note that this command omits fixtures with leading ``_`` unless the ``-v`` option is added.
265+
Note that this command omits fixtures with leading ``_`` unless the :option:`-v` option is added.
266266

267267
Continue reading
268268
-------------------------------------

0 commit comments

Comments
 (0)