Skip to content

Commit 231e2f9

Browse files
Merge pull request #2252 from nicoddemus/fixture-visibility-docs
Improve pytest_plugins docs
2 parents 427bf42 + c4d9744 commit 231e2f9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

doc/en/writing_plugins.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,31 @@ import ``helper.py`` normally. The contents of
236236
Requiring/Loading plugins in a test module or conftest file
237237
-----------------------------------------------------------
238238

239-
You can require plugins in a test module or a conftest file like this::
239+
You can require plugins in a test module or a ``conftest.py`` file like this:
240240

241-
pytest_plugins = "name1", "name2",
241+
.. code-block:: python
242+
243+
pytest_plugins = ["name1", "name2"]
242244
243245
When the test module or conftest plugin is loaded the specified plugins
244-
will be loaded as well. You can also use dotted path like this::
246+
will be loaded as well. Any module can be blessed as a plugin, including internal
247+
application modules:
248+
249+
.. code-block:: python
245250
246251
pytest_plugins = "myapp.testsupport.myplugin"
247252
248-
which will import the specified module as a ``pytest`` plugin.
253+
``pytest_plugins`` variables are processed recursively, so note that in the example above
254+
if ``myapp.testsupport.myplugin`` also declares ``pytest_plugins``, the contents
255+
of the variable will also be loaded as plugins, and so on.
256+
257+
This mechanism makes it easy to share textures within applications or even
258+
external applications without the need to create external plugins using
259+
the ``setuptools``'s entry point technique.
249260

250-
Plugins imported like this will automatically be marked to require
251-
assertion rewriting using the :func:`pytest.register_assert_rewrite`
252-
mechanism. However for this to have any effect the module must not be
261+
Plugins imported by ``pytest_plugins`` will also automatically be marked
262+
for assertion rewriting (see :func:`pytest.register_assert_rewrite`).
263+
However for this to have any effect the module must not be
253264
imported already; if it was already imported at the time the
254265
``pytest_plugins`` statement is processed, a warning will result and
255266
assertions inside the plugin will not be re-written. To fix this you

0 commit comments

Comments
 (0)