python config_error ai_generated true

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

ID: python/pytest-capture-logging-handler

Also available as: JSON · Markdown · 中文
80%Fix Rate
82%Confidence
0Evidence
2024-05-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
7.x active
8.x active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 50% fail

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

  2. 70% fail

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