{
  "id": "python/pytest-capture-logging-not-working",
  "signature": "Log message not captured in caplog.records",
  "signature_zh": "日志消息未被 caplog.records 捕获",
  "regex": "Log\\ message\\ not\\ captured\\ in\\ caplog\\.records",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "日志记录器未配置为使用 pytest 的捕获处理器，通常因为日志器名称错误或传播设置问题。",
  "root_cause_type": "generic",
  "root_cause_zh": "日志记录器未配置为使用 pytest 的捕获处理器，通常因为日志器名称错误或传播设置问题。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "在测试内配置 basicConfig",
      "why_fails": "尝试在测试中调用 logging.basicConfig，但 pytest 已经配置了处理器",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "错误地使用 __name__",
      "why_fails": "使用 logging.getLogger(__name__) 但测试模块名称与预期不符",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "确保日志器名称正确",
      "success_rate": 0.9,
      "how": "logger = logging.getLogger('my_module')\ncaplog.set_level(logging.INFO)\nlogger.info('test')",
      "condition": "",
      "sources": []
    },
    {
      "action": "配置文件配置",
      "success_rate": 0.8,
      "how": "在 conftest.py 中配置 logging 插件，确保传播开启",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}