Skip to content

Commit

Permalink
Merge pull request #2252 from nicoddemus/fixture-visibility-docs
Browse files Browse the repository at this point in the history
Improve pytest_plugins docs
  • Loading branch information
RonnyPfannschmidt committed Feb 15, 2017
2 parents 427bf42 + c4d9744 commit 231e2f9
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions doc/en/writing_plugins.rst
Expand Up @@ -236,20 +236,31 @@ import ``helper.py`` normally. The contents of
Requiring/Loading plugins in a test module or conftest file
-----------------------------------------------------------

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

pytest_plugins = "name1", "name2",
.. code-block:: python
pytest_plugins = ["name1", "name2"]
When the test module or conftest plugin is loaded the specified plugins
will be loaded as well. You can also use dotted path like this::
will be loaded as well. Any module can be blessed as a plugin, including internal
application modules:

.. code-block:: python
pytest_plugins = "myapp.testsupport.myplugin"
which will import the specified module as a ``pytest`` plugin.
``pytest_plugins`` variables are processed recursively, so note that in the example above
if ``myapp.testsupport.myplugin`` also declares ``pytest_plugins``, the contents
of the variable will also be loaded as plugins, and so on.

This mechanism makes it easy to share textures within applications or even
external applications without the need to create external plugins using
the ``setuptools``'s entry point technique.

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

5 comments on commit 231e2f9

@TristenHayfield
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

share textures

share fixtures

@RonnyPfannschmidt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, completely missed

@nicoddemus sorry it slipped my eyes

@nicoddemus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, will fix it directly on master.

@nicoddemus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all @RonnyPfannschmidt. Thanks @TristenHayfield for catching it.

Fixed in 8f98ac5.

@TristenHayfield
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.

Please sign in to comment.