{
  "id": "python/pytest-caplog-empty-no-propagate",
  "signature": "assert 0 == 1\nE   AssertionError: expected 1 log record, got 0\nE   assert 0 == 1\nE    +  where 0 = len(caplog.records)",
  "signature_zh": "assert 0 == 1\nE   AssertionError: 期望 1 条日志，实际 0 条\nE   assert 0 == 1\nE    +  其中 0 = len(caplog.records)",
  "regex": "assert\\ 0\\ ==\\ 1\\\nE\\ \\ \\ AssertionError:\\ expected\\ 1\\ log\\ record,\\ got\\ 0\\\nE\\ \\ \\ assert\\ 0\\ ==\\ 1\\\nE\\ \\ \\ \\ \\+\\ \\ where\\ 0\\ =\\ len\\(caplog\\.records\\)",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The application logger has propagate=False, or caplog's level is not set to the level of the emitted records, so records never reach the root handler that caplog attaches to.",
  "root_cause_type": "generic",
  "root_cause_zh": "应用 logger 设置了 propagate=False，或 caplog 的级别未设置为所发出记录的级别，导致记录无法到达 caplog 挂载的 root 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": "Clearing does not help when records never propagate to caplog in the first place.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Same propagation issue; caplog.text is also empty.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def test_logs(caplog):\n    caplog.set_level(logging.INFO, logger='myapp')\n    import logging\n    logging.getLogger('myapp').propagate = True\n    my_function()\n    assert 'started' in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "def test_logs(caplog):\n    with caplog.at_level(logging.INFO, logger='myapp'):\n        my_function()\n    assert any('started' in r.message for r in caplog.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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}