Skip to content

Commit ae51278

Browse files
committed
Rel 2; fixes reproducible builds when using explicit modules loading like: PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_PLUGINS=xyz,abc; see pytest-dev/pytest#12624
1 parent 4f1b816 commit ae51278

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

pytest-dev-bug-12624.patch

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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``.

python3-pytest.spec

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ Summary: Simple and popular testing tool for Python
1010
Summary(pl.UTF-8): Proste i popularne narzędzie testujące dla Pythona
1111
Name: python3-%{module}
1212
Version: 8.3.4
13-
Release: 1
13+
Release: 2
1414
License: MIT
1515
Group: Development/Languages/Python
1616
#Source0Download: https://pypi.org/simple/pytest/
1717
Source0: https://files.pythonhosted.org/packages/source/p/pytest/pytest-%{version}.tar.gz
1818
# Source0-md5: 542c4e802eeac1d196482e90a36533ed
19+
Patch0: pytest-dev-bug-12624.patch
1920
URL: https://pytest.org/
2021
BuildRequires: python3-build
2122
BuildRequires: python3-devel >= 1:3.7
@@ -97,6 +98,7 @@ Dokumentacja pakietu Pythona py.test.
9798

9899
%prep
99100
%setup -q -n %{module}-%{version}
101+
%patch -P0 -p1
100102

101103
%build
102104
export PYTEST_DISABLE_PLUGIN_AUTOLOAD=1

0 commit comments

Comments
 (0)