2020-01-10 05:06:15 +08:00
|
|
|
|
.. _`reference`:
|
|
|
|
|
|
2019-07-15 22:25:33 +08:00
|
|
|
|
API Reference
|
|
|
|
|
=============
|
2018-02-08 06:53:31 +08:00
|
|
|
|
|
|
|
|
|
This page contains the full reference to pytest's API.
|
|
|
|
|
|
2018-02-27 07:13:33 +08:00
|
|
|
|
.. contents::
|
2018-02-28 04:32:34 +08:00
|
|
|
|
:depth: 3
|
2018-02-27 07:27:15 +08:00
|
|
|
|
:local:
|
|
|
|
|
|
2018-03-02 05:07:06 +08:00
|
|
|
|
Functions
|
|
|
|
|
---------
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2018-02-28 05:26:40 +08:00
|
|
|
|
pytest.approx
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.approx
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.fail
|
|
|
|
|
~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2018-03-02 05:07:06 +08:00
|
|
|
|
**Tutorial**: :ref:`skipping`
|
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.fail
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.skip
|
|
|
|
|
~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.skip(msg, [allow_module_level=False])
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2019-08-10 03:35:03 +08:00
|
|
|
|
.. _`pytest.importorskip ref`:
|
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.importorskip
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.importorskip
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.xfail
|
|
|
|
|
~~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.xfail
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.exit
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.exit
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.main
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2020-06-14 21:52:09 +08:00
|
|
|
|
.. autofunction:: pytest.main
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2018-03-01 07:34:20 +08:00
|
|
|
|
pytest.param
|
2019-03-16 19:06:33 +08:00
|
|
|
|
~~~~~~~~~~~~
|
2018-03-01 07:34:20 +08:00
|
|
|
|
|
2018-03-02 04:54:54 +08:00
|
|
|
|
.. autofunction:: pytest.param(*values, [id], [marks])
|
2018-03-01 07:34:20 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.raises
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~~~
|
2018-02-27 07:57:02 +08:00
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :ref:`assertraises`.
|
|
|
|
|
|
2019-11-13 04:32:05 +08:00
|
|
|
|
.. autofunction:: pytest.raises(expected_exception: Exception [, *, match])
|
2018-02-27 07:57:02 +08:00
|
|
|
|
:with: excinfo
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2018-02-28 04:15:08 +08:00
|
|
|
|
pytest.deprecated_call
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2018-02-27 07:34:53 +08:00
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :ref:`ensuring_function_triggers`.
|
|
|
|
|
|
2018-03-02 04:54:54 +08:00
|
|
|
|
.. autofunction:: pytest.deprecated_call()
|
2018-02-27 07:57:02 +08:00
|
|
|
|
:with:
|
2018-02-08 06:53:31 +08:00
|
|
|
|
|
2018-03-02 04:54:54 +08:00
|
|
|
|
pytest.register_assert_rewrite
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2018-03-02 04:54:54 +08:00
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`assertion-rewriting`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: pytest.register_assert_rewrite
|
|
|
|
|
|
2018-02-28 05:26:40 +08:00
|
|
|
|
pytest.warns
|
2018-03-02 05:07:06 +08:00
|
|
|
|
~~~~~~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`assertwarnings`
|
|
|
|
|
|
2018-03-02 04:54:54 +08:00
|
|
|
|
.. autofunction:: pytest.warns(expected_warning: Exception, [match])
|
2018-02-28 05:26:40 +08:00
|
|
|
|
:with:
|
|
|
|
|
|
2018-10-02 22:39:08 +08:00
|
|
|
|
pytest.freeze_includes
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`freezing-pytest`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: pytest.freeze_includes
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
|
|
|
|
.. _`marks ref`:
|
|
|
|
|
|
2018-03-01 07:34:20 +08:00
|
|
|
|
Marks
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
|
|
Marks can be used apply meta data to *test functions* (but not fixtures), which can then be accessed by
|
|
|
|
|
fixtures or plugins.
|
|
|
|
|
|
|
|
|
|
|
2018-04-06 00:39:57 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-23 00:02:30 +08:00
|
|
|
|
.. _`pytest.mark.filterwarnings ref`:
|
|
|
|
|
|
|
|
|
|
pytest.mark.filterwarnings
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`filterwarnings`.
|
|
|
|
|
|
|
|
|
|
Add warning filters to marked test items.
|
|
|
|
|
|
|
|
|
|
.. py:function:: pytest.mark.filterwarnings(filter)
|
|
|
|
|
|
|
|
|
|
:keyword str filter:
|
|
|
|
|
A *warning specification string*, which is composed of contents of the tuple ``(action, message, category, module, lineno)``
|
|
|
|
|
as specified in `The Warnings filter <https://docs.python.org/3/library/warnings.html#warning-filter>`_ section of
|
|
|
|
|
the Python documentation, separated by ``":"``. Optional fields can be omitted.
|
2018-10-28 13:12:12 +08:00
|
|
|
|
Module names passed for filtering are not regex-escaped.
|
2018-03-23 00:02:30 +08:00
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2020-03-12 16:38:00 +08:00
|
|
|
|
@pytest.mark.filterwarnings("ignore:.*usage will be deprecated.*:DeprecationWarning")
|
2018-03-23 00:02:30 +08:00
|
|
|
|
def test_foo():
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
2018-03-01 07:34:20 +08:00
|
|
|
|
.. _`pytest.mark.parametrize ref`:
|
|
|
|
|
|
|
|
|
|
pytest.mark.parametrize
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`parametrize`.
|
|
|
|
|
|
2020-07-17 20:59:35 +08:00
|
|
|
|
This mark has the same signature as :py:meth:`_pytest.python.Metafunc.parametrize`; see there.
|
2018-03-01 07:34:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _`pytest.mark.skip ref`:
|
|
|
|
|
|
|
|
|
|
pytest.mark.skip
|
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`skip`.
|
|
|
|
|
|
|
|
|
|
Unconditionally skip a test function.
|
|
|
|
|
|
|
|
|
|
.. py:function:: pytest.mark.skip(*, reason=None)
|
|
|
|
|
|
|
|
|
|
:keyword str reason: Reason why the test function is being skipped.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _`pytest.mark.skipif ref`:
|
|
|
|
|
|
|
|
|
|
pytest.mark.skipif
|
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2018-05-17 21:15:47 +08:00
|
|
|
|
**Tutorial**: :ref:`skipif`.
|
2018-03-01 07:34:20 +08:00
|
|
|
|
|
|
|
|
|
Skip a test function if a condition is ``True``.
|
|
|
|
|
|
|
|
|
|
.. py:function:: pytest.mark.skipif(condition, *, reason=None)
|
|
|
|
|
|
|
|
|
|
:type condition: bool or str
|
|
|
|
|
:param condition: ``True/False`` if the condition should be skipped or a :ref:`condition string <string conditions>`.
|
|
|
|
|
:keyword str reason: Reason why the test function is being skipped.
|
|
|
|
|
|
|
|
|
|
|
2018-07-07 07:55:42 +08:00
|
|
|
|
.. _`pytest.mark.usefixtures ref`:
|
|
|
|
|
|
|
|
|
|
pytest.mark.usefixtures
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`usefixtures`.
|
|
|
|
|
|
|
|
|
|
Mark a test function as using the given fixture names.
|
|
|
|
|
|
|
|
|
|
.. py:function:: pytest.mark.usefixtures(*names)
|
|
|
|
|
|
2018-07-07 21:01:10 +08:00
|
|
|
|
:param args: the names of the fixture to use, as strings
|
2018-07-07 07:55:42 +08:00
|
|
|
|
|
2020-07-22 10:00:47 +08:00
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
When using `usefixtures` in hooks, it can only load fixtures when applied to a test function before test setup
|
|
|
|
|
(for example in the `pytest_collection_modifyitems` hook).
|
|
|
|
|
|
|
|
|
|
Also not that his mark has no effect when applied to **fixtures**.
|
|
|
|
|
|
|
|
|
|
|
2018-07-07 07:55:42 +08:00
|
|
|
|
|
2018-03-01 07:34:20 +08:00
|
|
|
|
.. _`pytest.mark.xfail ref`:
|
|
|
|
|
|
|
|
|
|
pytest.mark.xfail
|
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`xfail`.
|
|
|
|
|
|
|
|
|
|
Marks a test function as *expected to fail*.
|
|
|
|
|
|
|
|
|
|
.. py:function:: pytest.mark.xfail(condition=None, *, reason=None, raises=None, run=True, strict=False)
|
|
|
|
|
|
|
|
|
|
:type condition: bool or str
|
2019-03-17 17:14:40 +08:00
|
|
|
|
:param condition:
|
|
|
|
|
Condition for marking the test function as xfail (``True/False`` or a
|
2020-03-28 03:46:42 +08:00
|
|
|
|
:ref:`condition string <string conditions>`). If a bool, you also have
|
|
|
|
|
to specify ``reason`` (see :ref:`condition string <string conditions>`).
|
2018-03-01 07:34:20 +08:00
|
|
|
|
:keyword str reason: Reason why the test function is marked as xfail.
|
|
|
|
|
:keyword Exception raises: Exception subclass expected to be raised by the test function; other exceptions will fail the test.
|
|
|
|
|
:keyword bool run:
|
|
|
|
|
If the test function should actually be executed. If ``False``, the function will always xfail and will
|
2019-03-17 17:14:40 +08:00
|
|
|
|
not be executed (useful if a function is segfaulting).
|
2018-03-01 07:34:20 +08:00
|
|
|
|
:keyword bool strict:
|
|
|
|
|
* If ``False`` (the default) the function will be shown in the terminal output as ``xfailed`` if it fails
|
|
|
|
|
and as ``xpass`` if it passes. In both cases this will not cause the test suite to fail as a whole. This
|
2019-03-17 17:14:40 +08:00
|
|
|
|
is particularly useful to mark *flaky* tests (tests that fail at random) to be tackled later.
|
2018-03-01 07:34:20 +08:00
|
|
|
|
* If ``True``, the function will be shown in the terminal output as ``xfailed`` if it fails, but if it
|
|
|
|
|
unexpectedly passes then it will **fail** the test suite. This is particularly useful to mark functions
|
|
|
|
|
that are always failing and there should be a clear indication if they unexpectedly start to pass (for example
|
|
|
|
|
a new release of a library fixes a known bug).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
custom marks
|
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Marks are created dynamically using the factory object ``pytest.mark`` and applied as a decorator.
|
|
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2018-06-03 11:29:28 +08:00
|
|
|
|
@pytest.mark.timeout(10, "slow", method="thread")
|
2018-03-01 07:34:20 +08:00
|
|
|
|
def test_function():
|
|
|
|
|
...
|
|
|
|
|
|
2018-04-06 00:39:57 +08:00
|
|
|
|
Will create and attach a :class:`Mark <_pytest.mark.structures.Mark>` object to the collected
|
2018-03-01 07:34:20 +08:00
|
|
|
|
:class:`Item <_pytest.nodes.Item>`, which can then be accessed by fixtures or hooks with
|
2018-04-06 00:39:57 +08:00
|
|
|
|
:meth:`Node.iter_markers <_pytest.nodes.Node.iter_markers>`. The ``mark`` object will have the following attributes:
|
2018-03-01 07:34:20 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2018-06-03 11:29:28 +08:00
|
|
|
|
mark.args == (10, "slow")
|
|
|
|
|
mark.kwargs == {"method": "thread"}
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. _`fixtures-api`:
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
Fixtures
|
|
|
|
|
--------
|
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :ref:`fixture`.
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
Fixtures are requested by test functions or other fixtures by declaring them as argument names.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example of a test requiring a fixture:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
def test_output(capsys):
|
2018-06-03 11:29:28 +08:00
|
|
|
|
print("hello")
|
2018-02-09 05:57:26 +08:00
|
|
|
|
out, err = capsys.readouterr()
|
2018-06-03 11:29:28 +08:00
|
|
|
|
assert out == "hello\n"
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example of a fixture requiring another fixture:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def db_session(tmpdir):
|
2018-06-03 11:29:28 +08:00
|
|
|
|
fn = tmpdir / "db.file"
|
2018-02-09 05:57:26 +08:00
|
|
|
|
return connect(str(fn))
|
|
|
|
|
|
|
|
|
|
For more details, consult the full :ref:`fixtures docs <fixture>`.
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. _`pytest.fixture-api`:
|
|
|
|
|
|
2018-03-02 05:07:06 +08:00
|
|
|
|
@pytest.fixture
|
|
|
|
|
~~~~~~~~~~~~~~~
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2018-03-02 05:07:06 +08:00
|
|
|
|
.. autofunction:: pytest.fixture
|
2018-02-09 05:57:26 +08:00
|
|
|
|
:decorator:
|
|
|
|
|
|
|
|
|
|
|
2020-03-15 08:01:50 +08:00
|
|
|
|
.. fixture:: cache
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
|
|
|
|
config.cache
|
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :ref:`cache`.
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
The ``config.cache`` object allows other plugins and fixtures
|
|
|
|
|
to store and retrieve values across test runs. To access it from fixtures
|
|
|
|
|
request ``pytestconfig`` into your fixture and get it with ``pytestconfig.cache``.
|
|
|
|
|
|
|
|
|
|
Under the hood, the cache plugin uses the simple
|
|
|
|
|
``dumps``/``loads`` API of the :py:mod:`json` stdlib module.
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.cacheprovider
|
|
|
|
|
|
|
|
|
|
.. automethod:: Cache.get
|
|
|
|
|
.. automethod:: Cache.set
|
|
|
|
|
.. automethod:: Cache.makedir
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: capsys
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
capsys
|
|
|
|
|
~~~~~~
|
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :doc:`capture`.
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
.. currentmodule:: _pytest.capture
|
|
|
|
|
|
|
|
|
|
.. autofunction:: capsys()
|
2018-02-09 06:29:04 +08:00
|
|
|
|
:no-auto-options:
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
|
|
|
|
Returns an instance of :py:class:`CaptureFixture`.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
def test_output(capsys):
|
|
|
|
|
print("hello")
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
|
assert captured.out == "hello\n"
|
|
|
|
|
|
2018-03-02 10:33:21 +08:00
|
|
|
|
.. autoclass:: CaptureFixture()
|
|
|
|
|
:members:
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: capsysbinary
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
capsysbinary
|
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :doc:`capture`.
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
.. autofunction:: capsysbinary()
|
2018-02-09 06:29:04 +08:00
|
|
|
|
:no-auto-options:
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
|
|
|
|
Returns an instance of :py:class:`CaptureFixture`.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
def test_output(capsysbinary):
|
|
|
|
|
print("hello")
|
|
|
|
|
captured = capsysbinary.readouterr()
|
|
|
|
|
assert captured.out == b"hello\n"
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: capfd
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
capfd
|
|
|
|
|
~~~~~~
|
|
|
|
|
|
2018-02-28 04:58:51 +08:00
|
|
|
|
**Tutorial**: :doc:`capture`.
|
|
|
|
|
|
2018-02-09 05:57:26 +08:00
|
|
|
|
.. autofunction:: capfd()
|
2018-02-09 06:29:04 +08:00
|
|
|
|
:no-auto-options:
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
|
|
|
|
Returns an instance of :py:class:`CaptureFixture`.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
def test_system_echo(capfd):
|
|
|
|
|
os.system('echo "hello"')
|
2019-12-03 14:29:22 +08:00
|
|
|
|
captured = capfd.readouterr()
|
2018-03-01 07:52:41 +08:00
|
|
|
|
assert captured.out == "hello\n"
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: capfdbinary
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
capfdbinary
|
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`capture`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: capfdbinary()
|
|
|
|
|
:no-auto-options:
|
|
|
|
|
|
|
|
|
|
Returns an instance of :py:class:`CaptureFixture`.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
def test_system_echo(capfdbinary):
|
|
|
|
|
os.system('echo "hello"')
|
|
|
|
|
captured = capfdbinary.readouterr()
|
|
|
|
|
assert captured.out == b"hello\n"
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: doctest_namespace
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
doctest_namespace
|
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`doctest`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: _pytest.doctest.doctest_namespace()
|
|
|
|
|
|
|
|
|
|
Usually this fixture is used in conjunction with another ``autouse`` fixture:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def add_np(doctest_namespace):
|
2018-06-03 11:29:28 +08:00
|
|
|
|
doctest_namespace["np"] = numpy
|
2018-03-01 07:52:41 +08:00
|
|
|
|
|
|
|
|
|
For more details: :ref:`doctest_namespace`.
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: request
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
request
|
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`request example`.
|
|
|
|
|
|
|
|
|
|
The ``request`` fixture is a special fixture providing information of the requesting test function.
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.fixtures.FixtureRequest()
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: pytestconfig
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
pytestconfig
|
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
.. autofunction:: _pytest.fixtures.pytestconfig()
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: record_property
|
|
|
|
|
|
2018-03-17 05:15:28 +08:00
|
|
|
|
record_property
|
2018-03-01 07:52:41 +08:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2018-03-17 05:15:28 +08:00
|
|
|
|
**Tutorial**: :ref:`record_property example`.
|
2018-03-01 07:52:41 +08:00
|
|
|
|
|
2018-03-17 05:15:28 +08:00
|
|
|
|
.. autofunction:: _pytest.junitxml.record_property()
|
2018-03-01 07:52:41 +08:00
|
|
|
|
|
2019-05-04 03:30:16 +08:00
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: record_testsuite_property
|
|
|
|
|
|
2019-05-04 03:30:16 +08:00
|
|
|
|
record_testsuite_property
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`record_testsuite_property example`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: _pytest.junitxml.record_testsuite_property()
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
|
|
|
|
|
.. fixture:: caplog
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
caplog
|
|
|
|
|
~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`logging`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: _pytest.logging.caplog()
|
|
|
|
|
:no-auto-options:
|
|
|
|
|
|
|
|
|
|
This returns a :class:`_pytest.logging.LogCaptureFixture` instance.
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.logging.LogCaptureFixture
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: monkeypatch
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
monkeypatch
|
|
|
|
|
~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.monkeypatch
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`monkeypatch`.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: _pytest.monkeypatch.monkeypatch()
|
|
|
|
|
:no-auto-options:
|
|
|
|
|
|
|
|
|
|
This returns a :class:`MonkeyPatch` instance.
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.monkeypatch.MonkeyPatch
|
|
|
|
|
:members:
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
|
|
|
|
|
.. fixture:: testdir
|
2019-11-25 11:06:30 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
testdir
|
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.pytester
|
|
|
|
|
|
|
|
|
|
This fixture provides a :class:`Testdir` instance useful for black-box testing of test files, making it ideal to
|
|
|
|
|
test plugins.
|
|
|
|
|
|
2019-08-07 07:20:06 +08:00
|
|
|
|
To use it, include in your top-most ``conftest.py`` file:
|
2018-03-01 07:52:41 +08:00
|
|
|
|
|
2019-08-07 04:25:54 +08:00
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
2019-08-07 04:34:58 +08:00
|
|
|
|
pytest_plugins = "pytester"
|
2018-03-01 07:52:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. autoclass:: Testdir()
|
2018-08-20 12:11:31 +08:00
|
|
|
|
:members:
|
2018-03-01 07:52:41 +08:00
|
|
|
|
|
|
|
|
|
.. autoclass:: RunResult()
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: LineMatcher()
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: recwarn
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
recwarn
|
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`assertwarnings`
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.recwarn
|
|
|
|
|
|
|
|
|
|
.. autofunction:: recwarn()
|
|
|
|
|
:no-auto-options:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.recwarn.WarningsRecorder()
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
Each recorded warning is an instance of :class:`warnings.WarningMessage`.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
:class:`RecordedWarning` was changed from a plain class to a namedtuple in pytest 3.1
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated
|
|
|
|
|
differently; see :ref:`ensuring_function_triggers`.
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: tmp_path
|
|
|
|
|
|
2019-03-02 04:09:07 +08:00
|
|
|
|
tmp_path
|
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`tmpdir`
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.tmpdir
|
|
|
|
|
|
|
|
|
|
.. autofunction:: tmp_path()
|
|
|
|
|
:no-auto-options:
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: tmp_path_factory
|
|
|
|
|
|
2019-03-02 04:09:07 +08:00
|
|
|
|
tmp_path_factory
|
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`tmp_path_factory example`
|
|
|
|
|
|
|
|
|
|
.. _`tmp_path_factory factory api`:
|
|
|
|
|
|
|
|
|
|
``tmp_path_factory`` instances have the following methods:
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.tmpdir
|
|
|
|
|
|
|
|
|
|
.. automethod:: TempPathFactory.mktemp
|
|
|
|
|
.. automethod:: TempPathFactory.getbasetemp
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: tmpdir
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
tmpdir
|
|
|
|
|
~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`tmpdir`
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.tmpdir
|
|
|
|
|
|
|
|
|
|
.. autofunction:: tmpdir()
|
|
|
|
|
:no-auto-options:
|
|
|
|
|
|
|
|
|
|
|
2020-02-22 21:56:19 +08:00
|
|
|
|
.. fixture:: tmpdir_factory
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
tmpdir_factory
|
|
|
|
|
~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`tmpdir factory example`
|
|
|
|
|
|
|
|
|
|
.. _`tmpdir factory api`:
|
|
|
|
|
|
|
|
|
|
``tmpdir_factory`` instances have the following methods:
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.tmpdir
|
|
|
|
|
|
|
|
|
|
.. automethod:: TempdirFactory.mktemp
|
|
|
|
|
.. automethod:: TempdirFactory.getbasetemp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _`hook-reference`:
|
|
|
|
|
|
|
|
|
|
Hooks
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
|
|
**Tutorial**: :doc:`writing_plugins`.
|
|
|
|
|
|
|
|
|
|
.. currentmodule:: _pytest.hookspec
|
|
|
|
|
|
|
|
|
|
Reference to all hooks which can be implemented by :ref:`conftest.py files <localplugin>` and :ref:`plugins <plugins>`.
|
|
|
|
|
|
|
|
|
|
Bootstrapping hooks
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Bootstrapping hooks called for plugins registered early enough (internal and setuptools plugins).
|
|
|
|
|
|
|
|
|
|
.. autofunction:: pytest_load_initial_conftests
|
|
|
|
|
.. autofunction:: pytest_cmdline_preparse
|
|
|
|
|
.. autofunction:: pytest_cmdline_parse
|
|
|
|
|
.. autofunction:: pytest_cmdline_main
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2019-05-15 07:49:47 +08:00
|
|
|
|
.. _`initialization-hooks`:
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Initialization hooks
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Initialization hooks called for plugins and ``conftest.py`` files.
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_addoption
|
2018-03-02 04:55:45 +08:00
|
|
|
|
.. autofunction:: pytest_addhooks
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_configure
|
|
|
|
|
.. autofunction:: pytest_unconfigure
|
2018-03-30 06:48:48 +08:00
|
|
|
|
.. autofunction:: pytest_sessionstart
|
|
|
|
|
.. autofunction:: pytest_sessionfinish
|
2018-02-28 04:58:51 +08:00
|
|
|
|
|
2019-03-08 22:21:56 +08:00
|
|
|
|
.. autofunction:: pytest_plugin_registered
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Collection hooks
|
|
|
|
|
~~~~~~~~~~~~~~~~
|
2018-02-09 05:57:26 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
``pytest`` calls the following hooks for collecting files and directories:
|
2018-02-09 06:08:44 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_collection
|
|
|
|
|
.. autofunction:: pytest_ignore_collect
|
|
|
|
|
.. autofunction:: pytest_collect_directory
|
|
|
|
|
.. autofunction:: pytest_collect_file
|
2019-03-08 22:21:56 +08:00
|
|
|
|
.. autofunction:: pytest_pycollect_makemodule
|
2018-02-28 04:58:51 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
For influencing the collection of objects in Python modules
|
|
|
|
|
you can use the following hook:
|
2018-02-09 06:08:44 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_pycollect_makeitem
|
|
|
|
|
.. autofunction:: pytest_generate_tests
|
|
|
|
|
.. autofunction:: pytest_make_parametrize_id
|
2018-02-09 06:08:44 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
After collection is complete, you can modify the order of
|
|
|
|
|
items, delete or otherwise amend the test items:
|
2018-02-09 06:08:44 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_collection_modifyitems
|
2018-02-09 06:08:44 +08:00
|
|
|
|
|
2019-03-08 22:21:56 +08:00
|
|
|
|
.. autofunction:: pytest_collection_finish
|
|
|
|
|
|
2020-06-14 21:31:55 +08:00
|
|
|
|
Test running (runtest) hooks
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
All runtest related hooks receive a :py:class:`pytest.Item <_pytest.main.Item>` object.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: pytest_runtestloop
|
|
|
|
|
.. autofunction:: pytest_runtest_protocol
|
|
|
|
|
.. autofunction:: pytest_runtest_logstart
|
|
|
|
|
.. autofunction:: pytest_runtest_logfinish
|
|
|
|
|
.. autofunction:: pytest_runtest_setup
|
|
|
|
|
.. autofunction:: pytest_runtest_call
|
|
|
|
|
.. autofunction:: pytest_runtest_teardown
|
|
|
|
|
.. autofunction:: pytest_runtest_makereport
|
|
|
|
|
|
|
|
|
|
For deeper understanding you may look at the default implementation of
|
|
|
|
|
these hooks in :py:mod:`_pytest.runner` and maybe also
|
|
|
|
|
in :py:mod:`_pytest.pdb` which interacts with :py:mod:`_pytest.capture`
|
|
|
|
|
and its input/output capturing in order to immediately drop
|
|
|
|
|
into interactive debugging when a test failure occurs.
|
|
|
|
|
|
|
|
|
|
.. autofunction:: pytest_pyfunc_call
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Reporting hooks
|
|
|
|
|
~~~~~~~~~~~~~~~
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Session related reporting hooks:
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_collectstart
|
2019-03-08 22:21:56 +08:00
|
|
|
|
.. autofunction:: pytest_make_collect_report
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_itemcollected
|
|
|
|
|
.. autofunction:: pytest_collectreport
|
|
|
|
|
.. autofunction:: pytest_deselected
|
|
|
|
|
.. autofunction:: pytest_report_header
|
|
|
|
|
.. autofunction:: pytest_report_collectionfinish
|
|
|
|
|
.. autofunction:: pytest_report_teststatus
|
|
|
|
|
.. autofunction:: pytest_terminal_summary
|
|
|
|
|
.. autofunction:: pytest_fixture_setup
|
|
|
|
|
.. autofunction:: pytest_fixture_post_finalizer
|
2018-09-04 06:27:46 +08:00
|
|
|
|
.. autofunction:: pytest_warning_captured
|
2020-05-25 08:43:23 +08:00
|
|
|
|
.. autofunction:: pytest_warning_recorded
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2019-06-27 06:10:54 +08:00
|
|
|
|
Central hook for reporting about test execution:
|
2018-02-28 04:58:51 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_runtest_logreport
|
2018-02-27 07:27:15 +08:00
|
|
|
|
|
2019-06-27 06:10:54 +08:00
|
|
|
|
Assertion related hooks:
|
2018-02-28 04:13:14 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_assertrepr_compare
|
2019-06-27 06:10:54 +08:00
|
|
|
|
.. autofunction:: pytest_assertion_pass
|
2018-02-28 04:13:14 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Debugging/Interaction hooks
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2018-02-28 04:19:57 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
There are few hooks which can be used for special
|
|
|
|
|
reporting or interaction with exceptions:
|
2018-02-28 04:19:57 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autofunction:: pytest_internalerror
|
|
|
|
|
.. autofunction:: pytest_keyboard_interrupt
|
|
|
|
|
.. autofunction:: pytest_exception_interact
|
|
|
|
|
.. autofunction:: pytest_enter_pdb
|
2018-02-28 04:58:51 +08:00
|
|
|
|
|
2018-02-28 04:32:34 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Objects
|
|
|
|
|
-------
|
2018-02-28 04:32:34 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Full reference to objects accessible from :ref:`fixtures <fixture>` or :ref:`hooks <hook-reference>`.
|
2018-02-28 04:48:19 +08:00
|
|
|
|
|
2018-02-28 04:32:34 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
CallInfo
|
|
|
|
|
~~~~~~~~
|
2018-02-28 04:32:34 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.runner.CallInfo()
|
2018-02-28 04:32:34 +08:00
|
|
|
|
:members:
|
2018-02-28 04:48:19 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Class
|
|
|
|
|
~~~~~
|
2018-02-28 04:48:19 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.python.Class()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Collector
|
|
|
|
|
~~~~~~~~~
|
2018-02-28 04:48:19 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.nodes.Collector()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 04:48:19 +08:00
|
|
|
|
|
2020-06-14 21:02:25 +08:00
|
|
|
|
CollectReport
|
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
2020-06-14 17:42:09 +08:00
|
|
|
|
.. autoclass:: _pytest.reports.CollectReport()
|
2020-06-14 21:02:25 +08:00
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
:inherited-members:
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Config
|
|
|
|
|
~~~~~~
|
2018-02-28 04:48:19 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.config.Config()
|
2018-02-28 04:48:19 +08:00
|
|
|
|
:members:
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
ExceptionInfo
|
|
|
|
|
~~~~~~~~~~~~~
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest._code.ExceptionInfo
|
|
|
|
|
:members:
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2019-06-15 23:18:21 +08:00
|
|
|
|
|
|
|
|
|
pytest.ExitCode
|
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
2020-02-11 05:43:30 +08:00
|
|
|
|
.. autoclass:: _pytest.config.ExitCode
|
2019-06-15 23:18:21 +08:00
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
FixtureDef
|
|
|
|
|
~~~~~~~~~~
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.fixtures.FixtureDef()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
FSCollector
|
|
|
|
|
~~~~~~~~~~~
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.nodes.FSCollector()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Function
|
|
|
|
|
~~~~~~~~
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.python.Function()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Item
|
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.nodes.Item()
|
2018-02-28 05:03:35 +08:00
|
|
|
|
:members:
|
2018-03-01 07:52:41 +08:00
|
|
|
|
:show-inheritance:
|
2018-02-28 05:03:35 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
MarkDecorator
|
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.mark.MarkDecorator
|
2018-02-28 05:03:35 +08:00
|
|
|
|
:members:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-04-06 00:39:57 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
MarkGenerator
|
|
|
|
|
~~~~~~~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.mark.MarkGenerator
|
|
|
|
|
:members:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-04-06 00:39:57 +08:00
|
|
|
|
|
|
|
|
|
Mark
|
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.mark.structures.Mark
|
|
|
|
|
:members:
|
|
|
|
|
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Metafunc
|
|
|
|
|
~~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.python.Metafunc
|
2018-02-28 05:26:40 +08:00
|
|
|
|
:members:
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Module
|
|
|
|
|
~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.python.Module()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Node
|
|
|
|
|
~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.nodes.Node()
|
|
|
|
|
:members:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Parser
|
2018-02-28 05:26:40 +08:00
|
|
|
|
~~~~~~
|
|
|
|
|
|
2018-06-11 22:20:24 +08:00
|
|
|
|
.. autoclass:: _pytest.config.argparsing.Parser()
|
2018-03-01 07:52:41 +08:00
|
|
|
|
:members:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
PluginManager
|
|
|
|
|
~~~~~~~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: pluggy.PluginManager()
|
|
|
|
|
:members:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
PytestPluginManager
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.config.PytestPluginManager()
|
|
|
|
|
:members:
|
|
|
|
|
:undoc-members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
Session
|
|
|
|
|
~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
.. autoclass:: _pytest.main.Session()
|
|
|
|
|
:members:
|
|
|
|
|
:show-inheritance:
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2018-03-01 07:52:41 +08:00
|
|
|
|
TestReport
|
|
|
|
|
~~~~~~~~~~
|
2018-02-28 05:26:40 +08:00
|
|
|
|
|
2020-06-14 17:42:09 +08:00
|
|
|
|
.. autoclass:: _pytest.reports.TestReport()
|
2018-03-01 07:52:41 +08:00
|
|
|
|
:members:
|
2020-03-05 13:00:11 +08:00
|
|
|
|
:show-inheritance:
|
2018-03-01 07:52:41 +08:00
|
|
|
|
:inherited-members:
|
|
|
|
|
|
|
|
|
|
_Result
|
|
|
|
|
~~~~~~~
|
|
|
|
|
|
2020-03-05 12:55:04 +08:00
|
|
|
|
Result used within :ref:`hook wrappers <hookwrapper>`.
|
|
|
|
|
|
2018-07-30 07:50:24 +08:00
|
|
|
|
.. autoclass:: pluggy.callers._Result
|
2020-03-05 12:55:04 +08:00
|
|
|
|
.. automethod:: pluggy.callers._Result.get_result
|
|
|
|
|
.. automethod:: pluggy.callers._Result.force_result
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
2020-07-10 20:50:03 +08:00
|
|
|
|
Global Variables
|
|
|
|
|
----------------
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
2020-07-10 20:50:03 +08:00
|
|
|
|
pytest treats some global variables in a special manner when defined in a test module or
|
|
|
|
|
``conftest.py`` files.
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
|
|
|
|
|
2020-07-10 20:50:03 +08:00
|
|
|
|
.. globalvar:: collect_ignore
|
2019-02-07 00:15:28 +08:00
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`customizing-test-collection`
|
|
|
|
|
|
|
|
|
|
Can be declared in *conftest.py files* to exclude test directories or modules.
|
|
|
|
|
Needs to be ``list[str]``.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
collect_ignore = ["setup.py"]
|
|
|
|
|
|
|
|
|
|
|
2020-07-10 20:50:03 +08:00
|
|
|
|
.. globalvar:: collect_ignore_glob
|
2019-02-07 00:15:28 +08:00
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`customizing-test-collection`
|
|
|
|
|
|
|
|
|
|
Can be declared in *conftest.py files* to exclude test directories or modules
|
|
|
|
|
with Unix shell-style wildcards. Needs to be ``list[str]`` where ``str`` can
|
|
|
|
|
contain glob patterns.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
collect_ignore_glob = ["*_ignore.py"]
|
|
|
|
|
|
|
|
|
|
|
2020-07-10 20:50:03 +08:00
|
|
|
|
.. globalvar:: pytest_plugins
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`available installable plugins`
|
|
|
|
|
|
|
|
|
|
Can be declared at the **global** level in *test modules* and *conftest.py files* to register additional plugins.
|
|
|
|
|
Can be either a ``str`` or ``Sequence[str]``.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
pytest_plugins = "myapp.testsupport.myplugin"
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
pytest_plugins = ("myapp.testsupport.tools", "myapp.testsupport.regression")
|
|
|
|
|
|
|
|
|
|
|
2020-07-10 20:50:03 +08:00
|
|
|
|
.. globalvar:: pytestmark
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
|
|
|
|
**Tutorial**: :ref:`scoped-marking`
|
|
|
|
|
|
|
|
|
|
Can be declared at the **global** level in *test modules* to apply one or more :ref:`marks <marks ref>` to all
|
2020-07-10 20:50:03 +08:00
|
|
|
|
test functions and methods. Can be either a single mark or a list of marks (applied in left-to-right order).
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
import pytest
|
2018-06-03 11:29:28 +08:00
|
|
|
|
|
2018-03-02 05:20:55 +08:00
|
|
|
|
pytestmark = pytest.mark.webtest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
import pytest
|
2018-06-03 11:29:28 +08:00
|
|
|
|
|
Fix pytestmark syntax in reference.rst
pytest 4.3.1 throws an error if `pytestmark` is set to a tuple of marks; it appears to insist on a list.
With `pytestmark = [pytest.mark.api, pytest.mark.good]`:
```
============================== test session starts ==============================
platform win32 -- Python 3.6.3, pytest-4.3.1, py-1.8.0, pluggy-0.9.0
rootdir: C:\Temp\git\sphobjinv, inifile: tox.ini
plugins: timeout-1.3.3
collected 48 items / 41 deselected / 7 selected
tests\test_api_good.py ....... [100%]
==================== 7 passed, 41 deselected in 0.15 seconds ====================
```
With `pytestmark = (pytest.mark.api, pytest.mark.good)`:
```
==================================== ERRORS =====================================
____________________ ERROR collecting tests/test_api_good.py ____________________
env\lib\site-packages\_pytest\runner.py:226: in from_call
result = func()
env\lib\site-packages\_pytest\runner.py:289: in <lambda>
call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
env\lib\site-packages\_pytest\python.py:435: in collect
self._inject_setup_module_fixture()
env\lib\site-packages\_pytest\python.py:447: in _inject_setup_module_fixture
setup_module = _get_non_fixture_func(self.obj, "setUpModule")
env\lib\site-packages\_pytest\python.py:255: in obj
self.own_markers.extend(get_unpacked_marks(self.obj))
env\lib\site-packages\_pytest\mark\structures.py:244: in get_unpacked_marks
return normalize_mark_list(mark_list)
env\lib\site-packages\_pytest\mark\structures.py:259: in normalize_mark_list
raise TypeError("got {!r} instead of Mark".format(mark))
E TypeError: got (MarkDecorator(mark=Mark(name='api', args=(), kwargs={})), MarkDecorator(mark=Mark(name='good', args=(), kwargs={}))) instead of Mark
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
==================== 19 deselected, 1 error in 0.27 seconds =====================
```
2019-03-22 03:14:28 +08:00
|
|
|
|
pytestmark = [pytest.mark.integration, pytest.mark.slow]
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
|
|
|
|
Environment Variables
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
Environment variables that can be used to change pytest's behavior.
|
|
|
|
|
|
2020-03-27 09:40:25 +08:00
|
|
|
|
.. envvar:: PYTEST_ADDOPTS
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
|
|
|
|
This contains a command-line (parsed by the py:mod:`shlex` module) that will be **prepended** to the command line given
|
|
|
|
|
by the user, see :ref:`adding default options` for more information.
|
|
|
|
|
|
2020-07-10 19:49:10 +08:00
|
|
|
|
.. envvar:: PYTEST_CURRENT_TEST
|
|
|
|
|
|
|
|
|
|
This is not meant to be set by users, but is set by pytest internally with the name of the current test so other
|
|
|
|
|
processes can inspect it, see :ref:`pytest current test env` for more information.
|
|
|
|
|
|
2020-03-27 09:40:25 +08:00
|
|
|
|
.. envvar:: PYTEST_DEBUG
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
|
|
|
|
When set, pytest will print tracing and debug information.
|
|
|
|
|
|
2020-07-10 19:49:10 +08:00
|
|
|
|
.. envvar:: PYTEST_DISABLE_PLUGIN_AUTOLOAD
|
|
|
|
|
|
|
|
|
|
When set, disables plugin auto-loading through setuptools entrypoints. Only explicitly specified plugins will be
|
|
|
|
|
loaded.
|
|
|
|
|
|
2020-03-27 09:40:25 +08:00
|
|
|
|
.. envvar:: PYTEST_PLUGINS
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
|
|
|
|
Contains comma-separated list of modules that should be loaded as plugins:
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2018-06-06 06:27:59 +08:00
|
|
|
|
export PYTEST_PLUGINS=mymodule.plugin,xdist
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
2020-07-10 19:49:10 +08:00
|
|
|
|
.. envvar:: PY_COLORS
|
2018-08-07 04:17:24 +08:00
|
|
|
|
|
2020-07-10 19:49:10 +08:00
|
|
|
|
When set to ``1``, pytest will use color in terminal output.
|
|
|
|
|
When set to ``0``, pytest will not use color.
|
|
|
|
|
``PY_COLORS`` takes precedence over ``NO_COLOR`` and ``FORCE_COLOR``.
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
2020-07-10 19:49:10 +08:00
|
|
|
|
.. envvar:: NO_COLOR
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
2020-07-10 19:49:10 +08:00
|
|
|
|
When set (regardless of value), pytest will not use color in terminal output.
|
|
|
|
|
``PY_COLORS`` takes precedence over ``NO_COLOR``, which takes precedence over ``FORCE_COLOR``.
|
|
|
|
|
See `no-color.org <https://no-color.org/>`__ for other libraries supporting this community standard.
|
|
|
|
|
|
|
|
|
|
.. envvar:: FORCE_COLOR
|
|
|
|
|
|
|
|
|
|
When set (regardless of value), pytest will use color in terminal output.
|
|
|
|
|
``PY_COLORS`` and ``NO_COLOR`` take precedence over ``FORCE_COLOR``.
|
2018-03-07 07:40:07 +08:00
|
|
|
|
|
2019-05-09 03:42:49 +08:00
|
|
|
|
Exceptions
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
.. autoclass:: _pytest.config.UsageError()
|
2020-07-23 08:36:51 +08:00
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. _`warnings ref`:
|
|
|
|
|
|
|
|
|
|
Warnings
|
|
|
|
|
--------
|
|
|
|
|
|
|
|
|
|
Custom warnings generated in some situations such as improper usage or deprecated features.
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestAssertRewriteWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestCacheWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestCollectionWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestConfigWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestDeprecationWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestExperimentalApiWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestUnhandledCoroutineWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
.. autoclass:: pytest.PytestUnknownMarkWarning
|
|
|
|
|
:show-inheritance:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Consult the :ref:`internal-warnings` section in the documentation for more information.
|
2019-05-09 03:42:49 +08:00
|
|
|
|
|
2018-03-02 05:20:55 +08:00
|
|
|
|
|
2018-03-08 07:45:41 +08:00
|
|
|
|
.. _`ini options ref`:
|
|
|
|
|
|
|
|
|
|
Configuration Options
|
|
|
|
|
---------------------
|
|
|
|
|
|
2020-06-08 21:03:10 +08:00
|
|
|
|
Here is a list of builtin configuration options that may be written in a ``pytest.ini``, ``pyproject.toml``, ``tox.ini`` or ``setup.cfg``
|
|
|
|
|
file, usually located at the root of your repository. To see each file format in details, see
|
|
|
|
|
:ref:`config file formats`.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2019-01-10 05:52:08 +08:00
|
|
|
|
.. warning::
|
2020-06-08 21:03:10 +08:00
|
|
|
|
Usage of ``setup.cfg`` is not recommended except for very simple use cases. ``.cfg``
|
2019-01-10 05:52:08 +08:00
|
|
|
|
files use a different parser than ``pytest.ini`` and ``tox.ini`` which might cause hard to track
|
|
|
|
|
down problems.
|
2020-06-08 21:03:10 +08:00
|
|
|
|
When possible, it is recommended to use the latter files, or ``pyproject.toml``, to hold your pytest configuration.
|
2019-01-07 04:47:40 +08:00
|
|
|
|
|
2020-06-08 21:03:10 +08:00
|
|
|
|
Configuration options may be overwritten in the command-line by using ``-o/--override-ini``, which can also be
|
2018-03-08 07:45:41 +08:00
|
|
|
|
passed multiple times. The expected format is ``name=value``. For example::
|
|
|
|
|
|
|
|
|
|
pytest -o console_output_style=classic -o cache_dir=/tmp/mycache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: addopts
|
|
|
|
|
|
|
|
|
|
Add the specified ``OPTS`` to the set of command line arguments as if they
|
|
|
|
|
had been specified by the user. Example: if you have this ini file content:
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
|
[pytest]
|
|
|
|
|
addopts = --maxfail=2 -rf # exit after 2 failures, report fail info
|
|
|
|
|
|
2019-10-01 22:17:26 +08:00
|
|
|
|
issuing ``pytest test_hello.py`` actually means:
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2019-08-07 04:25:54 +08:00
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
2018-03-08 07:45:41 +08:00
|
|
|
|
pytest --maxfail=2 -rf test_hello.py
|
|
|
|
|
|
|
|
|
|
Default is to add no options.
|
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: cache_dir
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Sets a directory where stores content of cache plugin. Default directory is
|
2018-05-30 19:24:10 +08:00
|
|
|
|
``.pytest_cache`` which is created in :ref:`rootdir <rootdir>`. Directory may be
|
2018-03-13 06:33:34 +08:00
|
|
|
|
relative or absolute path. If setting relative path, then directory is created
|
|
|
|
|
relative to :ref:`rootdir <rootdir>`. Additionally path may contain environment
|
|
|
|
|
variables, that will be expanded. For more information about cache plugin
|
|
|
|
|
please refer to :ref:`cache_provider`.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: confcutdir
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Sets a directory where search upwards for ``conftest.py`` files stops.
|
|
|
|
|
By default, pytest will stop searching for ``conftest.py`` files upwards
|
|
|
|
|
from ``pytest.ini``/``tox.ini``/``setup.cfg`` of the project if any,
|
|
|
|
|
or up to the file-system root.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: console_output_style
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Sets the console output style while running tests:
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
* ``classic``: classic pytest output.
|
|
|
|
|
* ``progress``: like classic pytest output, but with a progress indicator.
|
2018-08-27 10:21:00 +08:00
|
|
|
|
* ``count``: like progress, but shows progress as the number of tests completed instead of a percent.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
The default is ``progress``, but you can fallback to ``classic`` if you prefer or
|
|
|
|
|
the new mode is causing unexpected problems:
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
|
[pytest]
|
2018-03-13 06:33:34 +08:00
|
|
|
|
console_output_style = classic
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: doctest_encoding
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Default encoding to use to decode text files with docstrings.
|
|
|
|
|
:doc:`See how pytest handles doctests <doctest>`.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: doctest_optionflags
|
|
|
|
|
|
|
|
|
|
One or more doctest flag names from the standard ``doctest`` module.
|
|
|
|
|
:doc:`See how pytest handles doctests <doctest>`.
|
|
|
|
|
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: empty_parameter_set_mark
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Allows to pick the action for empty parametersets in parameterization
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-05-13 18:06:09 +08:00
|
|
|
|
* ``skip`` skips tests with an empty parameterset (default)
|
|
|
|
|
* ``xfail`` marks tests with an empty parameterset as xfail(run=False)
|
2018-09-12 18:18:44 +08:00
|
|
|
|
* ``fail_at_collect`` raises an exception if parametrize collects an empty parameter set
|
2018-03-13 06:33:34 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
|
[pytest]
|
|
|
|
|
empty_parameter_set_mark = xfail
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
The default value of this option is planned to change to ``xfail`` in future releases
|
|
|
|
|
as this is considered less error prone, see `#3155 <https://github.com/pytest-dev/pytest/issues/3155>`_
|
|
|
|
|
for more details.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2019-06-23 06:22:43 +08:00
|
|
|
|
.. confval:: faulthandler_timeout
|
|
|
|
|
|
|
|
|
|
Dumps the tracebacks of all threads if a test takes longer than ``X`` seconds to run (including
|
|
|
|
|
fixture setup and teardown). Implemented using the `faulthandler.dump_traceback_later`_ function,
|
|
|
|
|
so all caveats there apply.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
|
[pytest]
|
|
|
|
|
faulthandler_timeout=5
|
|
|
|
|
|
|
|
|
|
For more information please refer to :ref:`faulthandler`.
|
|
|
|
|
|
|
|
|
|
.. _`faulthandler.dump_traceback_later`: https://docs.python.org/3/library/faulthandler.html#faulthandler.dump_traceback_later
|
|
|
|
|
|
|
|
|
|
|
2018-03-08 07:45:41 +08:00
|
|
|
|
.. confval:: filterwarnings
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
Sets a list of filters and actions that should be taken for matched
|
|
|
|
|
warnings. By default all warnings emitted during the test session
|
|
|
|
|
will be displayed in a summary at the end of the test session.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
|
[pytest]
|
|
|
|
|
filterwarnings =
|
|
|
|
|
error
|
|
|
|
|
ignore::DeprecationWarning
|
|
|
|
|
|
|
|
|
|
This tells pytest to ignore deprecation warnings and turn all other warnings
|
|
|
|
|
into errors. For more information please refer to :ref:`warnings`.
|
|
|
|
|
|
2019-05-30 08:13:16 +08:00
|
|
|
|
|
|
|
|
|
.. confval:: junit_duration_report
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.1
|
|
|
|
|
|
|
|
|
|
Configures how durations are recorded into the JUnit XML report:
|
|
|
|
|
|
|
|
|
|
* ``total`` (the default): duration times reported include setup, call, and teardown times.
|
|
|
|
|
* ``call``: duration times reported include only call times, excluding setup and teardown.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
junit_duration_report = call
|
|
|
|
|
|
|
|
|
|
|
2019-02-08 23:10:47 +08:00
|
|
|
|
.. confval:: junit_family
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.2
|
|
|
|
|
|
|
|
|
|
Configures the format of the generated JUnit XML file. The possible options are:
|
|
|
|
|
|
|
|
|
|
* ``xunit1`` (or ``legacy``): produces old style output, compatible with the xunit 1.0 format. **This is the default**.
|
|
|
|
|
* ``xunit2``: produces `xunit 2.0 style output <https://github.com/jenkinsci/xunit-plugin/blob/xunit-2.3.2/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd>`__,
|
|
|
|
|
which should be more compatible with latest Jenkins versions.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
junit_family = xunit2
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2019-05-30 08:13:16 +08:00
|
|
|
|
.. confval:: junit_logging
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2019-05-30 08:13:16 +08:00
|
|
|
|
.. versionadded:: 3.5
|
2020-01-16 18:47:00 +08:00
|
|
|
|
.. versionchanged:: 5.4
|
|
|
|
|
``log``, ``all``, ``out-err`` options added.
|
2019-05-30 08:13:16 +08:00
|
|
|
|
|
2020-01-16 18:47:00 +08:00
|
|
|
|
Configures if captured output should be written to the JUnit XML file. Valid values are:
|
|
|
|
|
|
|
|
|
|
* ``log``: write only ``logging`` captured output.
|
|
|
|
|
* ``system-out``: write captured ``stdout`` contents.
|
|
|
|
|
* ``system-err``: write captured ``stderr`` contents.
|
|
|
|
|
* ``out-err``: write both captured ``stdout`` and ``stderr`` contents.
|
|
|
|
|
* ``all``: write captured ``logging``, ``stdout`` and ``stderr`` contents.
|
|
|
|
|
* ``no`` (the default): no captured output is written.
|
2019-05-30 08:13:16 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
junit_logging = system-out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: junit_log_passing_tests
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 4.6
|
|
|
|
|
|
|
|
|
|
If ``junit_logging != "no"``, configures if the captured output should be written
|
|
|
|
|
to the JUnit XML file for **passing** tests. Default is ``True``.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
junit_log_passing_tests = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: junit_suite_name
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
To set the name of the root test suite xml item, you can configure the ``junit_suite_name`` option in your config file:
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. code-block:: ini
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
[pytest]
|
|
|
|
|
junit_suite_name = my_suite
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2019-10-08 05:56:28 +08:00
|
|
|
|
.. confval:: log_auto_indent
|
|
|
|
|
|
|
|
|
|
Allow selective auto-indentation of multiline log messages.
|
|
|
|
|
|
|
|
|
|
Supports command line option ``--log-auto-indent [value]``
|
|
|
|
|
and config option ``log_auto_indent = [value]`` to set the
|
|
|
|
|
auto-indentation behavior for all logging.
|
|
|
|
|
|
|
|
|
|
``[value]`` can be:
|
|
|
|
|
* True or "On" - Dynamically auto-indent multiline log messages
|
|
|
|
|
* False or "Off" or 0 - Do not auto-indent multiline log messages (the default behavior)
|
|
|
|
|
* [positive integer] - auto-indent multiline log messages by [value] spaces
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_auto_indent = False
|
|
|
|
|
|
|
|
|
|
Supports passing kwarg ``extra={"auto_indent": [value]}`` to
|
|
|
|
|
calls to ``logging.log()`` to specify auto-indentation behavior for
|
|
|
|
|
a specific entry in the log. ``extra`` kwarg overrides the value specified
|
|
|
|
|
on the command line or in the config.
|
|
|
|
|
|
2019-11-25 05:33:51 +08:00
|
|
|
|
.. confval:: log_cli
|
|
|
|
|
|
|
|
|
|
Enable log display during test run (also known as :ref:`"live logging" <live_logs>`).
|
|
|
|
|
The default is ``False``.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_cli = True
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
.. confval:: log_cli_date_format
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a :py:func:`time.strftime`-compatible string that will be used when formatting dates for live logging.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_cli_date_format = %Y-%m-%d %H:%M:%S
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`live_logs`.
|
|
|
|
|
|
|
|
|
|
.. confval:: log_cli_format
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a :py:mod:`logging`-compatible string used to format live logging messages.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_cli_format = %(asctime)s %(levelname)s %(message)s
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`live_logs`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_cli_level
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets the minimum log message level that should be captured for live logging. The integer value or
|
|
|
|
|
the names of the levels can be used.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
2018-03-23 00:02:30 +08:00
|
|
|
|
log_cli_level = INFO
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
For more information, see :ref:`live_logs`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_date_format
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a :py:func:`time.strftime`-compatible string that will be used when formatting dates for logging capture.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_date_format = %Y-%m-%d %H:%M:%S
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_file
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a file name relative to the ``pytest.ini`` file where log messages should be written to, in addition
|
|
|
|
|
to the other logging facilities that are active.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_file = logs/pytest-logs.txt
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_file_date_format
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a :py:func:`time.strftime`-compatible string that will be used when formatting dates for the logging file.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_file_date_format = %Y-%m-%d %H:%M:%S
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
.. confval:: log_file_format
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a :py:mod:`logging`-compatible string used to format logging messages redirected to the logging file.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_file_format = %(asctime)s %(levelname)s %(message)s
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
.. confval:: log_file_level
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets the minimum log message level that should be captured for the logging file. The integer value or
|
|
|
|
|
the names of the levels can be used.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_file_level = INFO
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_format
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets a :py:mod:`logging`-compatible string used to format captured logging messages.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_format = %(asctime)s %(levelname)s %(message)s
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_level
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
Sets the minimum log message level that should be captured for logging capture. The integer value or
|
|
|
|
|
the names of the levels can be used.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_level = INFO
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: log_print
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 07:09:05 +08:00
|
|
|
|
|
|
|
|
|
If set to ``False``, will disable displaying captured logging messages for failed tests.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
log_print = False
|
|
|
|
|
|
|
|
|
|
For more information, see :ref:`logging`.
|
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:43:04 +08:00
|
|
|
|
.. confval:: markers
|
|
|
|
|
|
2019-04-27 22:43:36 +08:00
|
|
|
|
When the ``--strict-markers`` or ``--strict`` command-line arguments are used,
|
|
|
|
|
only known markers - defined in code by core pytest or some plugin - are allowed.
|
2019-02-25 19:30:49 +08:00
|
|
|
|
|
2019-04-27 21:52:12 +08:00
|
|
|
|
You can list additional markers in this setting to add them to the whitelist,
|
|
|
|
|
in which case you probably want to add ``--strict-markers`` to ``addopts``
|
|
|
|
|
to avoid future regressions:
|
2018-03-13 06:43:04 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
2019-04-27 21:52:12 +08:00
|
|
|
|
addopts = --strict-markers
|
2018-03-13 06:43:04 +08:00
|
|
|
|
markers =
|
|
|
|
|
slow
|
|
|
|
|
serial
|
|
|
|
|
|
2020-05-22 22:33:50 +08:00
|
|
|
|
.. note::
|
|
|
|
|
The use of ``--strict-markers`` is highly preferred. ``--strict`` was kept for
|
|
|
|
|
backward compatibility only and may be confusing for others as it only applies to
|
|
|
|
|
markers and not to other options.
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: minversion
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Specifies a minimal pytest version required for running tests.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
# content of pytest.ini
|
|
|
|
|
[pytest]
|
2018-03-13 06:33:34 +08:00
|
|
|
|
minversion = 3.0 # will fail if we run with pytest-2.8
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: norecursedirs
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Set the directory basename patterns to avoid when recursing
|
|
|
|
|
for test discovery. The individual (fnmatch-style) patterns are
|
|
|
|
|
applied to the basename of a directory to decide if to recurse into it.
|
|
|
|
|
Pattern matching characters::
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
* matches everything
|
|
|
|
|
? matches any single character
|
|
|
|
|
[seq] matches any character in seq
|
|
|
|
|
[!seq] matches any char not in seq
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Default patterns are ``'.*', 'build', 'dist', 'CVS', '_darcs', '{arch}', '*.egg', 'venv'``.
|
|
|
|
|
Setting a ``norecursedirs`` replaces the default. Here is an example of
|
|
|
|
|
how to avoid certain directories:
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. code-block:: ini
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
[pytest]
|
|
|
|
|
norecursedirs = .svn _build tmp*
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
This would tell ``pytest`` to not look into typical subversion or
|
|
|
|
|
sphinx-build directories or into any ``tmp`` prefixed directory.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
Additionally, ``pytest`` will attempt to intelligently identify and ignore a
|
|
|
|
|
virtualenv by the presence of an activation script. Any directory deemed to
|
|
|
|
|
be the root of a virtual environment will not be considered during test
|
|
|
|
|
collection unless ``‑‑collect‑in‑virtualenv`` is given. Note also that
|
|
|
|
|
``norecursedirs`` takes precedence over ``‑‑collect‑in‑virtualenv``; e.g. if
|
|
|
|
|
you intend to run tests in a virtualenv with a base directory that matches
|
|
|
|
|
``'.*'`` you *must* override ``norecursedirs`` in addition to using the
|
|
|
|
|
``‑‑collect‑in‑virtualenv`` flag.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: python_classes
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
One or more name prefixes or glob-style patterns determining which classes
|
2018-08-22 21:37:35 +08:00
|
|
|
|
are considered for test collection. Search for multiple glob patterns by
|
|
|
|
|
adding a space between patterns. By default, pytest will consider any
|
2018-03-13 06:33:34 +08:00
|
|
|
|
class prefixed with ``Test`` as a test collection. Here is an example of how
|
|
|
|
|
to collect tests from classes that end in ``Suite``:
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. code-block:: ini
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
[pytest]
|
|
|
|
|
python_classes = *Suite
|
|
|
|
|
|
|
|
|
|
Note that ``unittest.TestCase`` derived classes are always collected
|
|
|
|
|
regardless of this option, as ``unittest``'s own collection framework is used
|
|
|
|
|
to collect those tests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: python_files
|
|
|
|
|
|
|
|
|
|
One or more Glob-style file patterns determining which python files
|
2018-08-22 21:37:35 +08:00
|
|
|
|
are considered as test modules. Search for multiple glob patterns by
|
2018-09-15 04:20:22 +08:00
|
|
|
|
adding a space between patterns:
|
2018-08-22 21:37:35 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
python_files = test_*.py check_*.py example_*.py
|
|
|
|
|
|
2018-09-15 04:20:22 +08:00
|
|
|
|
Or one per line:
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
python_files =
|
|
|
|
|
test_*.py
|
|
|
|
|
check_*.py
|
|
|
|
|
example_*.py
|
|
|
|
|
|
|
|
|
|
By default, files matching ``test_*.py`` and ``*_test.py`` will be considered
|
|
|
|
|
test modules.
|
2018-03-13 06:33:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: python_functions
|
|
|
|
|
|
|
|
|
|
One or more name prefixes or glob-patterns determining which test functions
|
2018-08-22 21:37:35 +08:00
|
|
|
|
and methods are considered tests. Search for multiple glob patterns by
|
|
|
|
|
adding a space between patterns. By default, pytest will consider any
|
2018-03-13 06:33:34 +08:00
|
|
|
|
function prefixed with ``test`` as a test. Here is an example of how
|
|
|
|
|
to collect test functions and methods that end in ``_test``:
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
|
|
|
|
[pytest]
|
2018-03-13 06:33:34 +08:00
|
|
|
|
python_functions = *_test
|
|
|
|
|
|
|
|
|
|
Note that this has no effect on methods that live on a ``unittest
|
|
|
|
|
.TestCase`` derived class, as ``unittest``'s own collection framework is used
|
|
|
|
|
to collect those tests.
|
|
|
|
|
|
|
|
|
|
See :ref:`change naming conventions` for more detailed examples.
|
|
|
|
|
|
|
|
|
|
|
2020-06-10 12:44:22 +08:00
|
|
|
|
.. confval:: required_plugins
|
2020-06-06 23:05:32 +08:00
|
|
|
|
|
|
|
|
|
A space separated list of plugins that must be present for pytest to run.
|
2020-06-13 23:22:18 +08:00
|
|
|
|
Plugins can be listed with or without version specifiers directly following
|
|
|
|
|
their name. Whitespace between different version specifiers is not allowed.
|
2020-06-12 20:27:55 +08:00
|
|
|
|
If any one of the plugins is not found, emit an error.
|
2020-06-06 23:05:32 +08:00
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
2020-06-13 23:22:18 +08:00
|
|
|
|
required_plugins = pytest-django>=3.0.0,<4.0.0 pytest-html pytest-xdist>=1.0.0
|
2020-06-06 23:05:32 +08:00
|
|
|
|
|
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
.. confval:: testpaths
|
|
|
|
|
|
2019-04-28 23:37:58 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
|
|
|
|
|
Sets list of directories that should be searched for tests when
|
|
|
|
|
no specific directories, files or test ids are given in the command line when
|
|
|
|
|
executing pytest from the :ref:`rootdir <rootdir>` directory.
|
|
|
|
|
Useful when all project tests are in a known location to speed up
|
|
|
|
|
test collection and to avoid picking up undesired tests by accident.
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
[pytest]
|
|
|
|
|
testpaths = testing doc
|
2018-03-13 06:27:17 +08:00
|
|
|
|
|
2018-03-13 06:33:34 +08:00
|
|
|
|
This tells pytest to only look for tests in ``testing`` and ``doc``
|
|
|
|
|
directories when executing from the root directory.
|
2018-03-08 07:45:41 +08:00
|
|
|
|
|
2018-03-13 06:43:04 +08:00
|
|
|
|
|
|
|
|
|
.. confval:: usefixtures
|
|
|
|
|
|
|
|
|
|
List of fixtures that will be applied to all test functions; this is semantically the same to apply
|
|
|
|
|
the ``@pytest.mark.usefixtures`` marker to all test functions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
usefixtures =
|
|
|
|
|
clean_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. confval:: xfail_strict
|
|
|
|
|
|
|
|
|
|
If set to ``True``, tests marked with ``@pytest.mark.xfail`` that actually succeed will by default fail the
|
|
|
|
|
test suite.
|
|
|
|
|
For more information, see :ref:`xfail strict tutorial`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
|
xfail_strict = True
|