{
  "id": "python/pytest-caplog-no-logs-captured",
  "signature": "AssertionError: assert 'user created' in []\n  where [] = caplog.messages",
  "signature_zh": "AssertionError：assert 'user created' in []\n  其中 [] = caplog.messages",
  "regex": "AssertionError:\\ assert\\ 'user\\ created'\\ in\\ \\[\\]\\\n\\ \\ where\\ \\[\\]\\ =\\ caplog\\.messages",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "caplog only captures records at WARNING or above by default when the root logger has no handler configured, or the application uses a custom logger with propagate=False. Propagation must be enabled for caplog to intercept records.",
  "root_cause_type": "generic",
  "root_cause_zh": "当根 logger 未配置 handler 时，caplog 默认只捕获 WARNING 及以上级别的记录；或者应用程序使用了 propagate=False 的自定义 logger。必须启用传播才能让 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": "Clearing removes whatever was captured; if nothing was captured to begin with, the list stays empty.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Logging does not necessarily write to stdout; the logger may use a file or syslog handler, so capsys captures nothing.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_create_user(caplog):\n    caplog.set_level(logging.INFO, logger='myapp')\n    create_user('a@b.com')\n    assert 'user created' in caplog.text\n\n# in myapp/__init__.py\nlogger = logging.getLogger('myapp')\nlogger.propagate = True",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "def test_create_user(caplog):\n    with caplog.at_level(logging.INFO, logger='myapp'):\n        create_user('a@b.com')\n    assert any('user created' 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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-21",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}