|
| 1 | +From de4b7b60405270a38a82c7c3cbf6da746bd55009 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Marcel Telka < [email protected]> |
| 3 | +Date: Tue, 16 Jul 2024 03:05:07 +0200 |
| 4 | +Subject: [PATCH] Load plugins referencing entry point name provided via config |
| 5 | + and env var |
| 6 | + |
| 7 | +This allows to load plugins via `PYTEST_PLUGINS` environment variable and |
| 8 | +`pytest_plugins` global variable using their names in installed package entry |
| 9 | +points. |
| 10 | + |
| 11 | +Closes #12624. |
| 12 | +--- |
| 13 | + AUTHORS | 1 + |
| 14 | + changelog/12624.improvement.rst | 5 +++++ |
| 15 | + doc/en/reference/reference.rst | 4 +++- |
| 16 | + src/_pytest/config/__init__.py | 2 +- |
| 17 | + 4 files changed, 10 insertions(+), 2 deletions(-) |
| 18 | + create mode 100644 changelog/12624.improvement.rst |
| 19 | + |
| 20 | +diff --git a/AUTHORS b/AUTHORS |
| 21 | +index 5c046ff5988..c6331cd022c 100644 |
| 22 | +--- a/AUTHORS |
| 23 | ++++ b/AUTHORS |
| 24 | +@@ -265,6 +265,7 @@ Mandeep Bhutani |
| 25 | + Manuel Krebber |
| 26 | + Marc Mueller |
| 27 | + Marc Schlaich |
| 28 | ++Marcel Telka |
| 29 | + Marcelo Duarte Trevisani |
| 30 | + Marcin Bachry |
| 31 | + Marc Bresson |
| 32 | +diff --git a/changelog/12624.improvement.rst b/changelog/12624.improvement.rst |
| 33 | +new file mode 100644 |
| 34 | +index 00000000000..7ca60d428dd |
| 35 | +--- /dev/null |
| 36 | ++++ b/changelog/12624.improvement.rst |
| 37 | +@@ -0,0 +1,5 @@ |
| 38 | ++Plugins specified in the :globalvar:`pytest_plugins` config setting and |
| 39 | ++:envvar:`PYTEST_PLUGINS` environment variable now allow using |
| 40 | ++:ref:`entry points <pip-installable plugins>` names additionally to the |
| 41 | ++importable definitions. Prior to this release, these identifiers used to only |
| 42 | ++work with the ``-p`` CLI option -- by :user:`mtelka` and :user:`webknjaz`. |
| 43 | +diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst |
| 44 | +index 26572174ad4..74d28aba431 100644 |
| 45 | +--- a/doc/en/reference/reference.rst |
| 46 | ++++ b/doc/en/reference/reference.rst |
| 47 | +@@ -1166,7 +1166,9 @@ specified plugins will be loaded. |
| 48 | + |
| 49 | + .. envvar:: PYTEST_PLUGINS |
| 50 | + |
| 51 | +-Contains comma-separated list of modules that should be loaded as plugins: |
| 52 | ++Contains comma-separated list of :term:`importable modules <Module>` |
| 53 | ++or :ref:`entry point names <pip-installable plugins>` that should be |
| 54 | ++loaded as plugins: |
| 55 | + |
| 56 | + .. code-block:: bash |
| 57 | + |
| 58 | +diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py |
| 59 | +index 6160f780b1b..8478b43e668 100644 |
| 60 | +--- a/src/_pytest/config/__init__.py |
| 61 | ++++ b/src/_pytest/config/__init__.py |
| 62 | +@@ -826,7 +826,7 @@ def _import_plugin_specs( |
| 63 | + ) -> None: |
| 64 | + plugins = _get_plugin_specs_as_list(spec) |
| 65 | + for import_spec in plugins: |
| 66 | +- self.import_plugin(import_spec) |
| 67 | ++ self.import_plugin(import_spec, consider_entry_points=True) |
| 68 | + |
| 69 | + def import_plugin(self, modname: str, consider_entry_points: bool = False) -> None: |
| 70 | + """Import a plugin with ``modname``. |
0 commit comments