{
  "id": "python/pytest-caplog-not-propagating",
  "signature": "AssertionError: assert 'expected message' in []\n# caplog.records is empty",
  "signature_zh": "AssertionError: assert 'expected message' in []\n# caplog.records 为空",
  "regex": "AssertionError:\\ assert\\ 'expected\\ message'\\ in\\ \\[\\]\\\n\\#\\ caplog\\.records\\ is\\ empty",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The logger's propagate flag is False, or the code uses a logger configured with a custom handler and propagate=False, so records never reach the root logger that caplog attaches to.",
  "root_cause_type": "generic",
  "root_cause_zh": "logger 的 propagate 标志为 False，或代码使用了 propagate=False 的自定义 handler 配置的 logger，记录无法到达 caplog 所附加的根 logger。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adjusts the level but does not change propagate; the record still never reaches caplog's handler.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adds a root handler but does not affect the child logger's propagate=False setting.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "def test_logs(caplog):\n    logging.getLogger('mypkg').propagate = True\n    with caplog.at_level(logging.INFO, logger='mypkg'):\n        mypkg.do_work()\n    assert 'expected message' in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "def test_logs(caplog):\n    logger = logging.getLogger('mypkg')\n    logger.addHandler(caplog.handler)\n    mypkg.do_work()\n    assert 'expected message' in caplog.text",
      "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-09-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}