Skip to content

Commit

Permalink
Load plugins referencing entry point name provided via config and env…
Browse files Browse the repository at this point in the history
… var

This allows to load plugins via `PYTEST_PLUGINS` environment variable and
`pytest_plugins` global variable using their names in installed package entry
points.

Closes #12624.
  • Loading branch information
mtelka committed Jul 16, 2024
1 parent 400b22d commit 106c135
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ Mandeep Bhutani
Manuel Krebber
Marc Mueller
Marc Schlaich
Marcel Telka
Marcelo Duarte Trevisani
Marcin Bachry
Marc Bresson
Expand Down
5 changes: 5 additions & 0 deletions changelog/12624.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Plugins specified in the :globalvar:`pytest_plugins` config setting and
:envvar:`PYTEST_PLUGINS` environment variable now allow using
:ref:`entry points <pip-installable plugins>` names additionally to the
importable definitions. Prior to this release, these identifiers used to only
work with the ``-p`` CLI option -- by :user:`mtelka` and :user:`webknjaz`.
4 changes: 3 additions & 1 deletion doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,9 @@ specified plugins will be loaded.

.. envvar:: PYTEST_PLUGINS

Contains comma-separated list of modules that should be loaded as plugins:
Contains comma-separated list of :term:`importable modules <Module>`
or :ref:`entry point names <pip-installable plugins>` that should be
loaded as plugins:

.. code-block:: bash
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def _import_plugin_specs(
) -> None:
plugins = _get_plugin_specs_as_list(spec)
for import_spec in plugins:
self.import_plugin(import_spec)
self.import_plugin(import_spec, consider_entry_points=True)

def import_plugin(self, modname: str, consider_entry_points: bool = False) -> None:
"""Import a plugin with ``modname``.
Expand Down

0 comments on commit 106c135

Please sign in to comment.