2010-11-02 07:53:53 +08:00
|
|
|
.. _`external plugins`:
|
2010-12-06 23:54:42 +08:00
|
|
|
.. _`extplugins`:
|
2015-04-25 17:29:11 +08:00
|
|
|
.. _`using plugins`:
|
|
|
|
|
|
|
|
Installing and Using plugins
|
|
|
|
============================
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2015-04-25 17:29:11 +08:00
|
|
|
This section talks about installing and using third party plugins.
|
|
|
|
For writing your own plugins, please refer to :ref:`writing-plugins`.
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2019-08-07 07:20:06 +08:00
|
|
|
Installing a third party plugin can be easily done with ``pip``:
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2019-08-07 04:25:54 +08:00
|
|
|
.. code-block:: bash
|
|
|
|
|
2010-11-02 07:53:53 +08:00
|
|
|
pip install pytest-NAME
|
|
|
|
pip uninstall pytest-NAME
|
|
|
|
|
2014-01-18 19:31:33 +08:00
|
|
|
If a plugin is installed, ``pytest`` automatically finds and integrates it,
|
2015-12-11 05:00:01 +08:00
|
|
|
there is no need to activate it.
|
|
|
|
|
|
|
|
Here is a little annotated list for some popular plugins:
|
2012-10-09 20:35:17 +08:00
|
|
|
|
|
|
|
.. _`django`: https://www.djangoproject.com/
|
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-django <https://pypi.org/project/pytest-django/>`_: write tests
|
2012-10-09 20:35:17 +08:00
|
|
|
for `django`_ apps, using pytest integration.
|
2010-12-06 23:54:42 +08:00
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-twisted <https://pypi.org/project/pytest-twisted/>`_: write tests
|
2012-10-22 15:32:41 +08:00
|
|
|
for `twisted <http://twistedmatrix.com>`_ apps, starting a reactor and
|
|
|
|
processing deferreds from test functions.
|
|
|
|
|
2019-02-08 06:59:10 +08:00
|
|
|
* `pytest-cov <https://pypi.org/project/pytest-cov/>`__:
|
2013-05-08 03:34:59 +08:00
|
|
|
coverage reporting, compatible with distributed testing
|
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-xdist <https://pypi.org/project/pytest-xdist/>`_:
|
2012-10-09 20:35:17 +08:00
|
|
|
to distribute tests to CPUs and remote hosts, to run in boxed
|
|
|
|
mode which allows to survive segmentation faults, to run in
|
2014-01-18 19:31:33 +08:00
|
|
|
looponfailing mode, automatically re-running failing tests
|
2016-08-23 10:35:41 +08:00
|
|
|
on file changes.
|
2012-10-09 20:35:17 +08:00
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-instafail <https://pypi.org/project/pytest-instafail/>`_:
|
2013-05-08 03:34:59 +08:00
|
|
|
to report failures while the test run is happening.
|
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-bdd <https://pypi.org/project/pytest-bdd/>`_ and
|
|
|
|
`pytest-konira <https://pypi.org/project/pytest-konira/>`_
|
2013-05-08 03:34:59 +08:00
|
|
|
to write tests using behaviour-driven testing.
|
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-timeout <https://pypi.org/project/pytest-timeout/>`_:
|
2012-10-09 20:35:17 +08:00
|
|
|
to timeout tests based on function marks or global definitions.
|
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-pep8 <https://pypi.org/project/pytest-pep8/>`_:
|
2011-02-17 21:46:40 +08:00
|
|
|
a ``--pep8`` option to enable PEP8 compliance checking.
|
2010-12-06 23:54:42 +08:00
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `pytest-flakes <https://pypi.org/project/pytest-flakes/>`_:
|
2015-12-11 05:00:01 +08:00
|
|
|
check source code with pyflakes.
|
|
|
|
|
2018-04-26 21:45:48 +08:00
|
|
|
* `oejskit <https://pypi.org/project/oejskit/>`_:
|
2016-01-11 14:11:46 +08:00
|
|
|
a plugin to run javascript unittests in live browsers.
|
2010-12-06 23:54:42 +08:00
|
|
|
|
2014-02-19 08:33:13 +08:00
|
|
|
To see a complete list of all plugins with their latest testing
|
2016-06-21 22:16:57 +08:00
|
|
|
status against different pytest and Python versions, please visit
|
2015-03-01 04:22:42 +08:00
|
|
|
`plugincompat <http://plugincompat.herokuapp.com/>`_.
|
2014-02-19 08:33:13 +08:00
|
|
|
|
2018-11-05 01:02:28 +08:00
|
|
|
You may also discover more plugins through a `pytest- pypi.org search`_.
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2018-11-05 01:02:28 +08:00
|
|
|
.. _`pytest- pypi.org search`: https://pypi.org/search/?q=pytest-
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2014-08-20 06:52:40 +08:00
|
|
|
|
2018-03-02 05:20:55 +08:00
|
|
|
.. _`available installable plugins`:
|
|
|
|
|
2010-11-02 07:53:53 +08:00
|
|
|
Requiring/Loading plugins in a test module or conftest file
|
2014-08-20 06:52:40 +08:00
|
|
|
-----------------------------------------------------------
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2018-10-10 00:30:56 +08:00
|
|
|
You can require plugins in a test module or a conftest file like this:
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2018-10-10 00:30:56 +08:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
pytest_plugins = ("myapp.testsupport.myplugin",)
|
2010-11-02 07:53:53 +08:00
|
|
|
|
|
|
|
When the test module or conftest plugin is loaded the specified plugins
|
2015-04-25 17:29:11 +08:00
|
|
|
will be loaded as well.
|
2010-11-02 07:53:53 +08:00
|
|
|
|
2018-02-21 07:27:24 +08:00
|
|
|
.. note::
|
|
|
|
Requiring plugins using a ``pytest_plugins`` variable in non-root
|
|
|
|
``conftest.py`` files is deprecated. See
|
2018-03-13 05:32:51 +08:00
|
|
|
:ref:`full explanation <requiring plugins in non-root conftests>`
|
2018-02-21 07:27:24 +08:00
|
|
|
in the Writing plugins section.
|
|
|
|
|
2019-02-07 04:51:05 +08:00
|
|
|
.. note::
|
|
|
|
The name ``pytest_plugins`` is reserved and should not be used as a
|
|
|
|
name for a custom plugin module.
|
|
|
|
|
|
|
|
|
2010-12-06 23:54:42 +08:00
|
|
|
.. _`findpluginname`:
|
|
|
|
|
|
|
|
Finding out which plugins are active
|
2014-08-20 06:52:40 +08:00
|
|
|
------------------------------------
|
2010-12-06 23:54:42 +08:00
|
|
|
|
|
|
|
If you want to find out which plugins are active in your
|
2019-08-07 07:20:06 +08:00
|
|
|
environment you can type:
|
2010-12-06 23:54:42 +08:00
|
|
|
|
2019-08-07 04:25:54 +08:00
|
|
|
.. code-block:: bash
|
|
|
|
|
2016-06-21 22:16:57 +08:00
|
|
|
pytest --trace-config
|
2010-12-06 23:54:42 +08:00
|
|
|
|
|
|
|
and will get an extended test header which shows activated plugins
|
|
|
|
and their names. It will also print local plugins aka
|
2017-11-04 02:37:18 +08:00
|
|
|
:ref:`conftest.py <conftest.py plugins>` files when they are loaded.
|
2010-12-06 23:54:42 +08:00
|
|
|
|
|
|
|
.. _`cmdunregister`:
|
|
|
|
|
2011-09-06 17:43:42 +08:00
|
|
|
Deactivating / unregistering a plugin by name
|
2014-08-20 06:52:40 +08:00
|
|
|
---------------------------------------------
|
2010-12-06 23:54:42 +08:00
|
|
|
|
2019-08-07 07:20:06 +08:00
|
|
|
You can prevent plugins from loading or unregister them:
|
2010-12-06 23:54:42 +08:00
|
|
|
|
2019-08-07 04:25:54 +08:00
|
|
|
.. code-block:: bash
|
|
|
|
|
2016-06-21 22:16:57 +08:00
|
|
|
pytest -p no:NAME
|
2010-12-06 23:54:42 +08:00
|
|
|
|
|
|
|
This means that any subsequent try to activate/load the named
|
2015-09-29 05:23:08 +08:00
|
|
|
plugin will not work.
|
|
|
|
|
|
|
|
If you want to unconditionally disable a plugin for a project, you can add
|
|
|
|
this option to your ``pytest.ini`` file:
|
|
|
|
|
|
|
|
.. code-block:: ini
|
|
|
|
|
|
|
|
[pytest]
|
|
|
|
addopts = -p no:NAME
|
|
|
|
|
|
|
|
Alternatively to disable it only in certain environments (for example in a
|
|
|
|
CI server), you can set ``PYTEST_ADDOPTS`` environment variable to
|
|
|
|
``-p no:name``.
|
|
|
|
|
|
|
|
See :ref:`findpluginname` for how to obtain the name of a plugin.
|
2010-11-06 18:38:53 +08:00
|
|
|
|
|
|
|
.. _`builtin plugins`:
|