{
  "id": "python/pytest-caplog-not-captured",
  "signature": "AssertionError: assert 'expected message' in []\n  where [] = caplog.messages",
  "signature_zh": "AssertionError: assert 'expected message' in []\n  其中 [] = caplog.messages",
  "regex": "AssertionError:\\ assert\\ 'expected\\ message'\\ in\\ \\[\\]\\\n\\ \\ where\\ \\[\\]\\ =\\ caplog\\.messages",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The logger used by the code under test has propagate=False, or logging was configured with a handler that bypasses the root logger, so caplog's root handler never receives the record.",
  "root_cause_type": "generic",
  "root_cause_zh": "被测代码使用的 logger 设置了 propagate=False，或日志配置使用了绕过根 logger 的 handler，导致 caplog 的根 handler 从未收到日志记录。",
  "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": "Level is not the issue if propagate=False; the record never reaches the root logger's handlers regardless of level.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Both attributes are populated from the same captured records; an empty capture yields empty results in either.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def test_x(caplog):\n    logging.getLogger('myapp').propagate = True\n    with caplog.at_level(logging.INFO, logger='myapp'):\n        run()\n    assert 'expected message' in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "import logging\n\ndef test_x():\n    records = []\n    h = logging.Handler()\n    h.emit = records.append\n    log = logging.getLogger('myapp')\n    log.addHandler(h)\n    try:\n        run()\n    finally:\n        log.removeHandler(h)\n    assert any('expected' in r.getMessage() for r in records)",
      "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-10-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}