{
  "id": "python/pytest-caplog-no-capture",
  "signature": "AssertionError: assert 'expected log' in []",
  "signature_zh": "AssertionError: assert 'expected log' in []",
  "regex": "AssertionError:\\ assert\\ 'expected\\ log'\\ in\\ \\[\\]",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "caplog captures via logging's root logger by default; if the code under test uses a custom logger with propagate=False or a different handler, caplog sees nothing.",
  "root_cause_type": "generic",
  "root_cause_zh": "caplog 默认通过 logging 的根 logger 捕获；若被测代码使用 propagate=False 的自定义 logger 或其他 handler，caplog 看不到任何内容。",
  "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": "Sets the level but does not fix propagation; if propagate=False, records still never reach caplog's handler.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adds a root handler but caplog replaces handlers per test; custom loggers with propagate=False still bypass.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "capsys captures stdout/stderr; logging output may not be written there depending on handler configuration.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def test_logs(caplog):\n    logger = logging.getLogger('myapp.worker')\n    logger.propagate = True\n    with caplog.at_level(logging.INFO):\n        run_worker()\n    assert 'expected log' in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "def test_logs(caplog):\n    logger = logging.getLogger('myapp.worker')\n    logger.addHandler(caplog.handler)\n    run_worker()\n    assert 'expected log' 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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}