pluggy.PluginValidationError: 无法加载插件 'pytest_cov': (pytest 8.2.0 (...), 要求 'pytest>=8.3') 错误: 插件已以不同名称注册
pluggy.PluginValidationError: Plugin 'pytest_cov' could not be loaded: (pytest 8.2.0 (...), requirement 'pytest>=8.3') ERROR: plugin already registered under a different name
ID: python/pytest-plugin-autoload-conflict
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
两个插件声明了相同的插件名,或某插件要求比已安装版本更新的 pytest。常见于混用 pytest-cov/pytest-xdist 版本,或本地 conftest 定义了名称冲突的 hookimpl。
English
Two plugins declare the same plugin name, or a plugin requires a newer pytest than installed. Common when mixing pytest-cov/pytest-xdist versions or when a local conftest defines a hookimpl with a conflicting name.
解决方案
-
93% 成功率
pip install -U "pytest>=8.3" pytest-cov pytest-xdist pip check
-
85% 成功率
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest -p pytest_cov -p pytest_xdist
无效尝试
常见但无效的做法:
-
70% 失败
Breaks other plugins expecting the newer pytest, causing a cascade of validation errors.
-
60% 失败
If the plugin is still auto-loaded via entry points, the conflict persists; you must also set PYTEST_DISABLE_PLUGIN_AUTOLOAD.