Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/8456.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :confval:`required_plugins` config option now works correctly when pre-releases of plugins are installed, rather than falsely claiming that those plugins aren't installed at all.
8 changes: 5 additions & 3 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,16 @@ def _validate_plugins(self) -> None:
missing_plugins = []
for required_plugin in required_plugins:
try:
spec = Requirement(required_plugin)
req = Requirement(required_plugin)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the freedom to rename this, as spec is very close to specifier (another thing in packaging, see .specifier below) which I found confusing.

except InvalidRequirement:
missing_plugins.append(required_plugin)
continue

if spec.name not in plugin_dist_info:
if req.name not in plugin_dist_info:
missing_plugins.append(required_plugin)
elif Version(plugin_dist_info[spec.name]) not in spec.specifier:
elif not req.specifier.contains(
Version(plugin_dist_info[req.name]), prereleases=True
):
missing_plugins.append(required_plugin)

if missing_plugins:
Expand Down
30 changes: 24 additions & 6 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,14 @@ def pytest_configure(config):
result.stdout.no_fnmatch_line("*PytestConfigWarning*")

@pytest.mark.parametrize(
"ini_file_text, exception_text",
"ini_file_text, plugin_version, exception_text",
[
pytest.param(
"""
[pytest]
required_plugins = a z
""",
"1.5",
"Missing required plugins: a, z",
id="2-missing",
),
Expand All @@ -324,6 +325,7 @@ def pytest_configure(config):
[pytest]
required_plugins = a z myplugin
""",
"1.5",
"Missing required plugins: a, z",
id="2-missing-1-ok",
),
Expand All @@ -332,6 +334,7 @@ def pytest_configure(config):
[pytest]
required_plugins = myplugin
""",
"1.5",
None,
id="1-ok",
),
Expand All @@ -340,6 +343,7 @@ def pytest_configure(config):
[pytest]
required_plugins = myplugin==1.5
""",
"1.5",
None,
id="1-ok-pin-exact",
),
Expand All @@ -348,23 +352,35 @@ def pytest_configure(config):
[pytest]
required_plugins = myplugin>1.0,<2.0
""",
"1.5",
None,
id="1-ok-pin-loose",
),
pytest.param(
"""
[pytest]
required_plugins = pyplugin==1.6
required_plugins = myplugin
""",
"1.5a1",
None,
id="1-ok-prerelease",
),
pytest.param(
"""
[pytest]
required_plugins = myplugin==1.6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the two commits individually to get a better diff (also see the comment below).

""",
"Missing required plugins: pyplugin==1.6",
"1.5",
"Missing required plugins: myplugin==1.6",
id="missing-version",
),
pytest.param(
"""
[pytest]
required_plugins = pyplugin==1.6 other==1.0
required_plugins = myplugin==1.6 other==1.0
""",
"Missing required plugins: other==1.0, pyplugin==1.6",
"1.5",
"Missing required plugins: myplugin==1.6, other==1.0",
id="missing-versions",
),
pytest.param(
Expand All @@ -373,6 +389,7 @@ def pytest_configure(config):
required_plugins = wont be triggered
[pytest]
""",
"1.5",
None,
id="invalid-header",
),
Expand All @@ -383,6 +400,7 @@ def test_missing_required_plugins(
pytester: Pytester,
monkeypatch: MonkeyPatch,
ini_file_text: str,
plugin_version: str,
exception_text: str,
) -> None:
"""Check 'required_plugins' option with various settings.
Expand All @@ -408,7 +426,7 @@ def load(self):
class DummyDist:
entry_points = attr.ib()
files = ()
version = "1.5"
version = plugin_version

@property
def metadata(self):
Expand Down