python install_error ai_generated true

pytest 配置错误:未知插件:'pytest-cov'

pytest.PytestConfigError: Unknown plugin: 'pytest-cov'

ID: python/pytest-missing-plugin

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-07-10首次发现

版本兼容性

版本状态引入弃用备注
3.11 active

根因分析

pytest 配置文件(pytest.ini、pyproject.toml 或 conftest.py)引用了当前 Python 环境中未安装的插件,导致 pytest 启动失败。

English

The pytest configuration (pytest.ini, pyproject.toml, or conftest.py) references a plugin that is not installed in the current Python environment, causing pytest to fail on startup.

generic

解决方案

  1. 95% 成功率
    Install the missing plugin using pip: pip install pytest-cov, then re-run pytest.
  2. 90% 成功率
    If the plugin is not needed, remove its reference from the configuration file (e.g., delete 'pytest-cov' from addopts or plugins list).

无效尝试

常见但无效的做法:

  1. 80% 失败

    Adding the plugin name to conftest.py's pytest_plugins list without installing it first still raises the same error.

  2. 50% 失败

    Ignoring the error and running tests with -p no:plugin may suppress the error but disables the plugin's functionality.