-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Improve docs about plugin discovery/loading at startup #7748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,26 +33,34 @@ Plugin discovery order at tool startup | |||||||||||||||||||
|
||||||||||||||||||||
``pytest`` loads plugin modules at tool startup in the following way: | ||||||||||||||||||||
|
||||||||||||||||||||
* by loading all builtin plugins | ||||||||||||||||||||
1. by scanning the command line for the ``-p no:name`` option | ||||||||||||||||||||
and *blocking* that plugin from being loaded (even builtin plugins can | ||||||||||||||||||||
be blocked this way). This happens before normal command-line parsing. | ||||||||||||||||||||
|
||||||||||||||||||||
* by loading all plugins registered through `setuptools entry points`_. | ||||||||||||||||||||
2. by loading all builtin plugins. | ||||||||||||||||||||
|
||||||||||||||||||||
* by pre-scanning the command line for the ``-p name`` option | ||||||||||||||||||||
and loading the specified plugin before actual command line parsing. | ||||||||||||||||||||
3. by scanning the command line for the ``-p name`` option | ||||||||||||||||||||
and loading the specified plugin. This happens before normal command-line parsing. | ||||||||||||||||||||
|
||||||||||||||||||||
* by loading all :file:`conftest.py` files as inferred by the command line | ||||||||||||||||||||
invocation: | ||||||||||||||||||||
4. by loading all plugins registered through `setuptools entry points`_. | ||||||||||||||||||||
|
||||||||||||||||||||
- if no test paths are specified use 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. | ||||||||||||||||||||
5. by loading all plugins specified through the :envvar:`PYTEST_PLUGINS` environment variable. | ||||||||||||||||||||
|
||||||||||||||||||||
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. | ||||||||||||||||||||
6. by loading all :file:`conftest.py` files as inferred by the command line | ||||||||||||||||||||
invocation: | ||||||||||||||||||||
|
||||||||||||||||||||
* by recursively loading all plugins specified by the | ||||||||||||||||||||
:globalvar:`pytest_plugins` variable in ``conftest.py`` files | ||||||||||||||||||||
- if no test paths are specified use 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`` | ||||||||||||||||||||
Comment on lines
+53
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really how it works?? (The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, this was copied from the previous text. No I don't think that's how it works, I will double check and update the text accordingly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow, it actually works this way: pytest/src/_pytest/config/__init__.py Lines 505 to 513 in d3f47bf
So that's correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eeek There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I concur... 😬 |
||||||||||||||||||||
file is loaded, 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/ | ||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.