Skip to content

required_plugins false-positive with prereleases of plugins #8456

@The-Compiler

Description

@The-Compiler

With a pytest.ini like

[pytest]
required_plugins = pytest-qt pytest-bdd

when those plugins are installed from VCS, pytest doesn't seem to detect pytest-qt (and some others), while pytest-bdd (and some others) are fine.

To reproduce:

$ python3 -m venv .venv
$ .venv/bin/pip install -qU pip setuptools wheel
$ .venv/bin/pip install pytest git+https://github.com/pytest-dev/pytest-qt.git git+https://github.com/pytest-dev/pytest-bdd.git
[...]
Successfully installed [...] packaging-20.9 parse-1.19.0 [...] pluggy-0.13.1 py-1.10.0 [...] pytest-6.2.2 pytest-bdd-4.0.2 pytest-qt-3.3.1.dev71+g1fbdd94 [...]

$ cat > pytest.ini
[pytest]
required_plugins = pytest-qt pytest-bdd

$ ./.venv/bin/pytest   
ERROR: Missing required plugins: pytest-qt

$ .venv/bin/pip freeze                  
[...]
pytest-bdd @ git+https://github.com/pytest-dev/pytest-bdd.git@5d58fe3bbbf38d2408701f4876281a3440890522
pytest-qt @ git+https://github.com/pytest-dev/pytest-qt.git@1fbdd944d33c49662894661b4071fb641a681b21
[...]

Looking at it with a debugger, apparently this condition:

elif Version(plugin_dist_info[spec.name]) not in spec.specifier:

works fine for pytest-bdd:

> .../_pytest/config/__init__.py(1273)_validate_plugins()
-> try:
(Pdb) required_plugin
'pytest-bdd'

(Pdb) n
> .../_pytest/config/__init__.py(1281)_validate_plugins()
-> elif Version(plugin_dist_info[spec.name]) not in spec.specifier:

(Pdb) plugin_dist_info[spec.name]
'4.0.2'

(Pdb) spec.specifier
<SpecifierSet('')>

(Pdb) plugin_dist_info[spec.name] in spec.specifier
True

but not pytest-qt:

(Pdb) required_plugin
'pytest-qt'

(Pdb) n
> .../_pytest/config/__init__.py(1281)_validate_plugins()
-> elif Version(plugin_dist_info[spec.name]) not in spec.specifier:

(Pdb) plugin_dist_info[spec.name]
'3.3.1.dev71+g1fbdd94'

(Pdb) spec.specifier
<SpecifierSet('')>

(Pdb) plugin_dist_info[spec.name] in spec.specifier
False

(Pdb) n
> /home/florian/proj/pytest/src/_pytest/config/__init__.py(1282)_validate_plugins()
-> missing_plugins.append(required_plugin)

I'm not sure why that is - I suspect setuptools-scm comes into play somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: configrelated to config handling, argument parsing and config file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions