python config_error ai_generated true

日志处理程序:'caplog' fixture需要'logging'插件,但日志未配置

logging.Handler: 'caplog' fixture requires 'logging' plugin, but logging is not configured

ID: python/pytest-capture-logging-handler

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

版本兼容性

版本状态引入弃用备注
7.x active
8.x active

根因分析

pytest的caplog fixture需要pytest的logging插件,如果插件被禁用或未安装,就会报错。

English

pytest的caplog fixture需要pytest的logging插件,如果插件被禁用或未安装,就会报错。

generic

解决方案

  1. 90% 成功率
    pip install pytest-logging
    # 在pytest.ini中添加
    [pytest]
    log_cli = true
  2. 80% 成功率
    [pytest]
    addopts = -p no:logging

无效尝试

常见但无效的做法:

  1. 50% 失败

    问题不是pytest未安装,而是插件未启用

  2. 70% 失败

    caplog是pytest内置的,手动配置不会影响pytest的捕获