From 606b2cdd5fc988babd86c5818ff09b892dd8fd08 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Tue, 16 Jul 2024 03:05:07 +0200 Subject: [PATCH] Consider entry_points for PYTEST_PLUGINS and pytest_plugins This fixes two issues related to the `PYTEST_PLUGINS` environment variable and `pytest_plugins` global variable: * plugins loaded this way are not listed in the list of plugins, * it is not possible to load plugins using their names in `entry_points.txt` files. Fixes #12615. --- AUTHORS | 1 + changelog/12615.bugfix.rst | 5 +++++ doc/en/reference/reference.rst | 2 +- src/_pytest/config/__init__.py | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelog/12615.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 8d31170560c..1b8d48e9ff7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -257,6 +257,7 @@ Mandeep Bhutani Manuel Krebber Marc Mueller Marc Schlaich +Marcel Telka Marcelo Duarte Trevisani Marcin Bachry Marc Bresson diff --git a/changelog/12615.bugfix.rst b/changelog/12615.bugfix.rst new file mode 100644 index 00000000000..56f790eb07a --- /dev/null +++ b/changelog/12615.bugfix.rst @@ -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 ` names additionally to the +importable definitions. Prior to this release, these identifiers used to only +work with the ``-p`` CLI option. -- by :user:`mtelka`. diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index d1222728e13..4911f16aa92 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -1153,7 +1153,7 @@ 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 modules or entry points that should be loaded as plugins: .. code-block:: bash diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 0c1850df503..bb8cf4b0ad9 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -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``.