Debian Codegraph @

testing/web-platform/tests/tools/third_party/pytest/doc/en/how-to/plugins.rst

raw
1 .. _`external plugins`:
2 .. _`extplugins`:
3 .. _`using plugins`:
4
5 How to install and use plugins
6 ===============================
7
8 This section talks about installing and using third party plugins.
9 For writing your own plugins, please refer to :ref:`writing-plugins`.
10
11 Installing a third party plugin can be easily done with ``pip``:
12
13 .. code-block:: bash
14
15 pip install pytest-NAME
16 pip uninstall pytest-NAME
17
18 If a plugin is installed, ``pytest`` automatically finds and integrates it,
19 there is no need to activate it.
20
21 Here is a little annotated list for some popular plugins:
22
23 * :pypi:`pytest-django`: write tests
24 for `django <https://docs.djangoproject.com/>`_ apps, using pytest integration.
25
26 * :pypi:`pytest-twisted`: write tests
27 for `twisted <https://twistedmatrix.com/>`_ apps, starting a reactor and
28 processing deferreds from test functions.
29
30 * :pypi:`pytest-cov`:
31 coverage reporting, compatible with distributed testing
32
33 * :pypi:`pytest-xdist`:
34 to distribute tests to CPUs and remote hosts, to run in boxed
35 mode which allows to survive segmentation faults, to run in
36 looponfailing mode, automatically re-running failing tests
37 on file changes.
38
39 * :pypi:`pytest-instafail`:
40 to report failures while the test run is happening.
41
42 * :pypi:`pytest-bdd`:
43 to write tests using behaviour-driven testing.
44
45 * :pypi:`pytest-timeout`:
46 to timeout tests based on function marks or global definitions.
47
48 * :pypi:`pytest-pep8`:
49 a ``--pep8`` option to enable PEP8 compliance checking.
50
51 * :pypi:`pytest-flakes`:
52 check source code with pyflakes.
53
54 * :pypi:`allure-pytest`:
55 report test results via `allure-framework <https://github.com/allure-framework/>`_.
56
57 To see a complete list of all plugins with their latest testing
58 status against different pytest and Python versions, please visit
59 :ref:`plugin-list`.
60
61 You may also discover more plugins through a `pytest- pypi.org search`_.
62
63 .. _`pytest- pypi.org search`: https://pypi.org/search/?q=pytest-
64
65
66 .. _`available installable plugins`:
67
68 Requiring/Loading plugins in a test module or conftest file
69 -----------------------------------------------------------
70
71 You can require plugins in a test module or a conftest file using :globalvar:`pytest_plugins`:
72
73 .. code-block:: python
74
75 pytest_plugins = ("myapp.testsupport.myplugin",)
76
77 When the test module or conftest plugin is loaded the specified plugins
78 will be loaded as well.
79
80 .. note::
81
82 Requiring plugins using a ``pytest_plugins`` variable in non-root
83 ``conftest.py`` files is deprecated. See
84 :ref:`full explanation <requiring plugins in non-root conftests>`
85 in the Writing plugins section.
86
87 .. note::
88 The name ``pytest_plugins`` is reserved and should not be used as a
89 name for a custom plugin module.
90
91
92 .. _`findpluginname`:
93
94 Finding out which plugins are active
95 ------------------------------------
96
97 If you want to find out which plugins are active in your
98 environment you can type:
99
100 .. code-block:: bash
101
102 pytest --trace-config
103
104 and will get an extended test header which shows activated plugins
105 and their names. It will also print local plugins aka
106 :ref:`conftest.py <conftest.py plugins>` files when they are loaded.
107
108 .. _`cmdunregister`:
109
110 Deactivating / unregistering a plugin by name
111 ---------------------------------------------
112
113 You can prevent plugins from loading or unregister them:
114
115 .. code-block:: bash
116
117 pytest -p no:NAME
118
119 This means that any subsequent try to activate/load the named
120 plugin will not work.
121
122 If you want to unconditionally disable a plugin for a project, you can add
123 this option to your ``pytest.ini`` file:
124
125 .. code-block:: ini
126
127 [pytest]
128 addopts = -p no:NAME
129
130 Alternatively to disable it only in certain environments (for example in a
131 CI server), you can set ``PYTEST_ADDOPTS`` environment variable to
132 ``-p no:name``.
133
134 See :ref:`findpluginname` for how to obtain the name of a plugin.
135
136 .. _`builtin plugins`: