Skip to content

Commit

Permalink
Merge pull request #11843 from bluetech/writing-plugins
Browse files Browse the repository at this point in the history
doc/writing_plugins: correct inaccuracies re. initial conftest loading
  • Loading branch information
bluetech authored Jan 19, 2024
2 parents d71ef04 + 111ad26 commit c3fc717
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions doc/en/how-to/writing_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,18 @@ Plugin discovery order at tool startup

5. by loading all plugins specified through the :envvar:`PYTEST_PLUGINS` environment variable.

6. by loading all :file:`conftest.py` files as inferred by the command line
invocation:
6. by loading all "initial ":file:`conftest.py` files:

- if no test paths are specified, use the current dir as a test path
- if exists, load ``conftest.py`` and ``test*/conftest.py`` relative
to the directory part of the first test path. After the ``conftest.py``
file is loaded, load all plugins specified in its
:globalvar:`pytest_plugins` variable if present.
- determine the test paths: specified on the command line, otherwise in
:confval:`testpaths` if defined and running from the rootdir, otherwise the
current dir
- for each test path, load ``conftest.py`` and ``test*/conftest.py`` relative
to the directory part of the test path, if exist. Before a ``conftest.py``
file is loaded, load ``conftest.py`` files in all of its parent directories.
After a ``conftest.py`` file is loaded, recursively load all plugins specified
in its :globalvar:`pytest_plugins` variable if present.

Note that pytest does not find ``conftest.py`` files in deeper nested
sub directories at tool startup. It is usually a good idea to keep
your ``conftest.py`` file in the top level test or project root directory.

7. by recursively loading all plugins specified by the
:globalvar:`pytest_plugins` variable in ``conftest.py`` files.


.. _`pytest/plugin`: http://bitbucket.org/pytest-dev/pytest/src/tip/pytest/plugin/
.. _`conftest.py plugins`:
.. _`localplugin`:
.. _`local conftest plugins`:
Expand Down Expand Up @@ -108,9 +102,9 @@ Here is how you might run it::
See also: :ref:`pythonpath`.

.. note::
Some hooks should be implemented only in plugins or conftest.py files situated at the
tests root directory due to how pytest discovers plugins during startup,
see the documentation of each hook for details.
Some hooks cannot be implemented in conftest.py files which are not
:ref:`initial <pluginorder>` due to how pytest discovers plugins during
startup. See the documentation of each hook for details.

Writing your own plugin
-----------------------
Expand Down

0 comments on commit c3fc717

Please sign in to comment.