{
  "id": "python/pytest-capture-log-with-caplog-and-capsys",
  "signature": "AssertionError: assert 'starting' in capsys.readouterr().out\nE       AssertionError: assert 'starting' in ''",
  "signature_zh": "AssertionError：assert 'starting' in capsys.readouterr().out\nE       AssertionError：assert 'starting' in ''",
  "regex": "AssertionError:\\ assert\\ 'starting'\\ in\\ capsys\\.readouterr\\(\\)\\.out\\\nE\\ \\ \\ \\ \\ \\ \\ AssertionError:\\ assert\\ 'starting'\\ in\\ ''",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The message was emitted via logging, not print, so capsys captured nothing. Logging writes to stderr through the logging handler, not stdout.",
  "root_cause_type": "generic",
  "root_cause_zh": "该消息通过 logging 发出，而不是 print，因此 capsys 没有捕获到任何内容。日志记录通过日志处理器写入 stderr，而不是 stdout。",
  "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": "Nothing was written to stdout in the first place.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Same stream issue; binary vs text doesn't help.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Pollutes production code to satisfy a test.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_start(caplog):\n    with caplog.at_level(\"INFO\"):\n        start()\n    assert \"starting\" in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "def test_start(capsys):\n    start()\n    captured = capsys.readouterr()\n    assert \"starting\" in captured.err",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-12-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}