Fix sphinx code-block types (syntax highlighting) in two docs
This commit is contained in:
parent
8726be27a6
commit
799bcccd1b
|
@ -4,9 +4,11 @@ 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:
|
||||
|
||||
pytest --doctest-glob='*.rst'
|
||||
.. code-block:: bash
|
||||
|
||||
$ pytest --doctest-glob='*.rst'
|
||||
|
||||
on the command line. Since version ``2.9``, ``--doctest-glob``
|
||||
can be given multiple times in the command-line.
|
||||
|
@ -26,9 +28,11 @@ 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):
|
||||
|
||||
pytest --doctest-modules
|
||||
.. code-block:: bash
|
||||
|
||||
$ pytest --doctest-modules
|
||||
|
||||
You can make these changes permanent in your project by
|
||||
putting them into a pytest.ini file like this:
|
||||
|
@ -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
|
||||
|
||||
# content of example.rst
|
||||
|
||||
|
@ -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
|
||||
|
||||
# content of example.rst
|
||||
>>> tmp = getfixture('tmpdir')
|
||||
|
@ -112,16 +120,20 @@ 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:
|
||||
|
||||
pytest --doctest-modules --doctest-continue-on-failure
|
||||
.. code-block:: bash
|
||||
|
||||
$ pytest --doctest-modules --doctest-continue-on-failure
|
||||
|
||||
|
||||
.. _`doctest_namespace`:
|
||||
|
@ -167,10 +179,12 @@ 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`):
|
||||
|
||||
pytest --doctest-modules --doctest-report none
|
||||
pytest --doctest-modules --doctest-report udiff
|
||||
pytest --doctest-modules --doctest-report cdiff
|
||||
pytest --doctest-modules --doctest-report ndiff
|
||||
pytest --doctest-modules --doctest-report only_first_failure
|
||||
.. code-block:: bash
|
||||
|
||||
$ pytest --doctest-modules --doctest-report none
|
||||
$ pytest --doctest-modules --doctest-report udiff
|
||||
$ pytest --doctest-modules --doctest-report cdiff
|
||||
$ pytest --doctest-modules --doctest-report ndiff
|
||||
$ pytest --doctest-modules --doctest-report only_first_failure
|
||||
|
|
|
@ -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
|
||||
|
@ -54,9 +56,11 @@ Keeping duplicate paths specified from command line
|
|||
----------------------------------------------------
|
||||
|
||||
Default behavior of ``pytest`` is to ignore duplicate paths specified from the command line.
|
||||
Example::
|
||||
Example:
|
||||
|
||||
pytest path_a path_a
|
||||
.. code-block:: pytest
|
||||
|
||||
$ pytest path_a path_a
|
||||
|
||||
...
|
||||
collected 1 item
|
||||
|
@ -65,9 +69,11 @@ Example::
|
|||
Just collect tests once.
|
||||
|
||||
To collect duplicate tests, use the ``--keep-duplicates`` option on the cli.
|
||||
Example::
|
||||
Example:
|
||||
|
||||
pytest --keep-duplicates path_a path_a
|
||||
.. code-block:: pytest
|
||||
|
||||
$ pytest --keep-duplicates path_a path_a
|
||||
|
||||
...
|
||||
collected 2 items
|
||||
|
@ -75,9 +81,11 @@ 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:
|
||||
|
||||
pytest test_a.py test_a.py
|
||||
.. code-block:: pytest
|
||||
|
||||
$ pytest test_a.py test_a.py
|
||||
|
||||
...
|
||||
collected 2 items
|
||||
|
@ -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]
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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:
|
||||
|
||||
pytest --pyargs unittest2.test.test_skipping -q
|
||||
.. 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]
|
||||
|
@ -185,7 +203,7 @@ You can always peek at the collection tree without running tests like this:
|
|||
|
||||
.. code-block:: pytest
|
||||
|
||||
. $ pytest --collect-only pythoncollection.py
|
||||
$ pytest --collect-only pythoncollection.py
|
||||
=========================== test session starts ============================
|
||||
platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y
|
||||
cachedir: $PYTHON_PREFIX/.pytest_cache
|
||||
|
@ -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]
|
||||
|
@ -243,7 +263,7 @@ leave out the ``setup.py`` file:
|
|||
|
||||
.. code-block:: pytest
|
||||
|
||||
#$ pytest --collect-only
|
||||
$ pytest --collect-only
|
||||
====== test session starts ======
|
||||
platform linux2 -- Python 2.7.10, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
|
||||
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
|
||||
|
|
Loading…
Reference in New Issue