Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions doc/en/bash-completion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ When using bash as your shell, ``pytest`` can use argcomplete
(https://argcomplete.readthedocs.io/) for auto-completion.
For this ``argcomplete`` needs to be installed **and** enabled.

Install argcomplete using::
Install argcomplete using:

sudo pip install 'argcomplete>=0.5.7'
.. code-block:: bash

For global activation of all argcomplete enabled python applications run::
sudo pip install 'argcomplete>=0.5.7'

For global activation of all argcomplete enabled python applications run:

.. code-block:: bash

sudo activate-global-python-argcomplete

For permanent (but not global) ``pytest`` activation, use::
For permanent (but not global) ``pytest`` activation, use:

.. code-block:: bash

register-python-argcomplete pytest >> ~/.bashrc

register-python-argcomplete pytest >> ~/.bashrc
For one-time activation of argcomplete for ``pytest`` only, use:

For one-time activation of argcomplete for ``pytest`` only, use::
.. code-block:: bash

eval "$(register-python-argcomplete pytest)"
eval "$(register-python-argcomplete pytest)"
8 changes: 6 additions & 2 deletions doc/en/cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ Behavior when no tests failed in the last run

When no tests failed in the last run, or when no cached ``lastfailed`` data was
found, ``pytest`` can be configured either to run all of the tests or no tests,
using the ``--last-failed-no-failures`` option, which takes one of the following values::
using the ``--last-failed-no-failures`` option, which takes one of the following values:

.. code-block:: bash

pytest --last-failed --last-failed-no-failures all # run all tests (default behavior)
pytest --last-failed --last-failed-no-failures none # run no tests and exit
Expand Down Expand Up @@ -283,7 +285,9 @@ Clearing Cache content
-------------------------------

You can instruct pytest to clear all cache files and values
by adding the ``--cache-clear`` option like this::
by adding the ``--cache-clear`` option like this:

.. code-block:: bash

pytest --cache-clear

Expand Down
4 changes: 3 additions & 1 deletion doc/en/capture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ There are two ways in which ``pytest`` can perform capturing:

.. _`disable capturing`:

You can influence output capturing mechanisms from the command line::
You can influence output capturing mechanisms from the command line:

.. code-block:: bash

pytest -s # disable all capturing
pytest --capture=sys # replace sys.stdout/stderr with in-mem files
Expand Down
28 changes: 21 additions & 7 deletions doc/en/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Command line options and configuration file settings
-----------------------------------------------------------------

You can get help on command line options and values in INI-style
configurations files by using the general help option::
configurations files by using the general help option:

.. code-block:: bash

pytest -h # prints options _and_ config file settings

Expand Down Expand Up @@ -92,12 +94,16 @@ The rootdir is used a reference directory for constructing test
addresses ("nodeids") and can be used also by plugins for storing
per-testrun information.

Example::
Example:

.. code-block:: bash

pytest path/to/testdir path/other/

will determine the common ancestor as ``path`` and then
check for ini-files as follows::
check for ini-files as follows:

.. code-block:: text

# first look for pytest.ini files
path/pytest.ini
Expand Down Expand Up @@ -133,19 +139,27 @@ progress output, you can write it into a configuration file:
addopts = -ra -q

Alternatively, you can set a ``PYTEST_ADDOPTS`` environment variable to add command
line options while the environment is in use::
line options while the environment is in use:

.. code-block:: bash

export PYTEST_ADDOPTS="-v"

Here's how the command-line is built in the presence of ``addopts`` or the environment variable::
Here's how the command-line is built in the presence of ``addopts`` or the environment variable:

.. code-block:: text

<pytest.ini:addopts> $PYTEST_ADDOPTS <extra command-line arguments>

So if the user executes in the command-line::
So if the user executes in the command-line:

.. code-block:: bash

pytest -m slow

The actual command line executed is::
The actual command line executed is:

.. code-block:: bash

pytest -ra -q -v -m slow

Expand Down
28 changes: 21 additions & 7 deletions doc/en/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Doctest integration for modules and test files

By default all files matching the ``test*.txt`` pattern will
be run through the python standard ``doctest`` module. You
can change the pattern by issuing::
can change the pattern by issuing:

.. code-block:: bash

pytest --doctest-glob='*.rst'

Expand All @@ -26,7 +28,9 @@ can be given multiple times in the command-line.

You can also trigger running of doctests
from docstrings in all python modules (including regular
python test modules)::
python test modules):

.. code-block:: bash

pytest --doctest-modules

Expand All @@ -39,7 +43,9 @@ putting them into a pytest.ini file like this:
[pytest]
addopts = --doctest-modules

If you then have a text file like this::
If you then have a text file like this:

.. code-block:: text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rst instead of text?


# content of example.rst

Expand Down Expand Up @@ -73,7 +79,9 @@ then you can just invoke ``pytest`` without command line options:

========================= 1 passed in 0.12 seconds =========================

It is possible to use fixtures using the ``getfixture`` helper::
It is possible to use fixtures using the ``getfixture`` helper:

.. code-block:: text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rst instead of text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried it first, but those files have doctest-syntax (valid python) and plain text as comments (valid for doctests). And no actual rst markup.
As as result there is no improvement in how they look on a web-page.


# content of example.rst
>>> tmp = getfixture('tmpdir')
Expand Down Expand Up @@ -112,14 +120,18 @@ the ``doctest_optionflags`` ini option:


Alternatively, it can be enabled by an inline comment in the doc test
itself::
itself:

.. code-block:: rst

# content of example.rst
>>> get_unicode_greeting() # doctest: +ALLOW_UNICODE
'Hello'

By default, pytest would report only the first failure for a given doctest. If
you want to continue the test even when you have failures, do::
you want to continue the test even when you have failures, do:

.. code-block:: bash

pytest --doctest-modules --doctest-continue-on-failure

Expand Down Expand Up @@ -167,7 +179,9 @@ Output format
You can change the diff output format on failure for your doctests
by using one of standard doctest modules format in options
(see :data:`python:doctest.REPORT_UDIFF`, :data:`python:doctest.REPORT_CDIFF`,
:data:`python:doctest.REPORT_NDIFF`, :data:`python:doctest.REPORT_ONLY_FIRST_FAILURE`)::
:data:`python:doctest.REPORT_NDIFF`, :data:`python:doctest.REPORT_ONLY_FIRST_FAILURE`):

.. code-block:: bash

pytest --doctest-modules --doctest-report none
pytest --doctest-modules --doctest-report udiff
Expand Down
12 changes: 9 additions & 3 deletions doc/en/example/markers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,18 @@ Registering markers

.. ini-syntax for custom markers:

Registering markers for your test suite is simple::
Registering markers for your test suite is simple:

.. code-block:: ini

# content of pytest.ini
[pytest]
markers =
webtest: mark a test as a webtest.

You can ask which markers exist for your test suite - the list includes our just defined ``webtest`` markers::
You can ask which markers exist for your test suite - the list includes our just defined ``webtest`` markers:

.. code-block:: pytest

$ pytest --markers
@pytest.mark.webtest: mark a test as a webtest.
Expand Down Expand Up @@ -388,7 +392,9 @@ and here is one that specifies exactly the environment needed:

========================= 1 passed in 0.12 seconds =========================

The ``--markers`` option always gives you a list of available markers::
The ``--markers`` option always gives you a list of available markers:

.. code-block:: pytest

$ pytest --markers
@pytest.mark.env(name): mark test to run only on named environment
Expand Down
40 changes: 30 additions & 10 deletions doc/en/example/pythoncollection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Ignore paths during test collection

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

.. code-block:: text

tests/
|-- example
Expand Down Expand Up @@ -54,7 +56,9 @@ Keeping duplicate paths specified from command line
----------------------------------------------------

Default behavior of ``pytest`` is to ignore duplicate paths specified from the command line.
Example::
Example:

.. code-block:: pytest

pytest path_a path_a

Expand All @@ -65,7 +69,9 @@ Example::
Just collect tests once.

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

.. code-block:: pytest

pytest --keep-duplicates path_a path_a

Expand All @@ -75,7 +81,9 @@ Example::

As the collector just works on directories, if you specify twice a single test file, ``pytest`` will
still collect it twice, no matter if the ``--keep-duplicates`` is not specified.
Example::
Example:

.. code-block:: pytest

pytest test_a.py test_a.py

Expand All @@ -87,7 +95,9 @@ Example::
Changing directory recursion
-----------------------------------------------------

You can set the :confval:`norecursedirs` option in an ini-file, for example your ``pytest.ini`` in the project root directory::
You can set the :confval:`norecursedirs` option in an ini-file, for example your ``pytest.ini`` in the project root directory:

.. code-block:: ini

# content of pytest.ini
[pytest]
Expand All @@ -103,7 +113,9 @@ Changing naming conventions
You can configure different naming conventions by setting
the :confval:`python_files`, :confval:`python_classes` and
:confval:`python_functions` configuration options.
Here is an example::
Here is an example:

.. code-block:: ini

# content of pytest.ini
# Example 1: have pytest look for "check" instead of "test"
Expand Down Expand Up @@ -142,7 +154,9 @@ The test collection would look like this:

======================= no tests ran in 0.12 seconds =======================

You can check for multiple glob patterns by adding a space between the patterns::
You can check for multiple glob patterns by adding a space between the patterns:

.. code-block:: ini

# Example 2: have pytest look for files with "test" and "example"
# content of pytest.ini, tox.ini, or setup.cfg file (replace "pytest"
Expand All @@ -162,13 +176,17 @@ Interpreting cmdline arguments as Python packages
You can use the ``--pyargs`` option to make ``pytest`` try
interpreting arguments as python package names, deriving
their file system path and then running the test. For
example if you have unittest2 installed you can type::
example if you have unittest2 installed you can type:

.. code-block:: bash

pytest --pyargs unittest2.test.test_skipping -q

which would run the respective test module. Like with
other options, through an ini-file and the :confval:`addopts` option you
can make this change more permanently::
can make this change more permanently:

.. code-block:: ini

# content of pytest.ini
[pytest]
Expand Down Expand Up @@ -206,7 +224,9 @@ Customizing test collection

.. regendoc:wipe

You can easily instruct ``pytest`` to discover tests from every Python file::
You can easily instruct ``pytest`` to discover tests from every Python file:

.. code-block:: ini

# content of pytest.ini
[pytest]
Expand Down
8 changes: 6 additions & 2 deletions doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,9 @@ and run them:
test_module.py:6: AssertionError
========================= 2 failed in 0.12 seconds =========================

you will have a "failures" file which contains the failing test ids::
you will have a "failures" file which contains the failing test ids:

.. code-block:: bash

$ cat failures
test_module.py::test_fail1 (PYTEST_TMPDIR/test_fail10)
Expand Down Expand Up @@ -935,6 +937,8 @@ like ``pytest-timeout`` they must be imported explicitly and passed on to pytest


This allows you to execute tests using the frozen
application with standard ``pytest`` command-line options::
application with standard ``pytest`` command-line options:

.. code-block:: bash

./app_main --pytest --verbose --tb=long --junitxml=results.xml test-suite/
12 changes: 9 additions & 3 deletions doc/en/fixture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ with a list of available function arguments.

.. note::

You can always issue ::
You can always issue:

.. code-block:: bash

pytest --fixtures test_simplefactory.py

Expand Down Expand Up @@ -362,7 +364,9 @@ The ``print`` and ``smtp.close()`` statements will execute when the last test in
the module has finished execution, regardless of the exception status of the
tests.

Let's execute it::
Let's execute it:

.. code-block:: pytest

$ pytest -s -q --tb=no
FFteardown smtp
Expand Down Expand Up @@ -471,7 +475,9 @@ read an optional server URL from the test module which uses our fixture::

We use the ``request.module`` attribute to optionally obtain an
``smtpserver`` attribute from the test module. If we just execute
again, nothing much has changed::
again, nothing much has changed:

.. code-block:: pytest

$ pytest -s -q --tb=no
FFfinalizing <smtplib.SMTP object at 0xdeadbeef> (smtp.gmail.com)
Expand Down
Loading