{
  "id": "python/pytest-capsys-not-captured",
  "signature": "AssertionError: assert '' == 'hello\\n'\n  +  where '' = capsys.readouterr().out",
  "signature_zh": "AssertionError: assert '' == 'hello\\n'\n  +  其中 '' = capsys.readouterr().out",
  "regex": "AssertionError:\\ assert\\ ''\\ ==\\ 'hello\\\\n'\\\n\\ \\ \\+\\ \\ where\\ ''\\ =\\ capsys\\.readouterr\\(\\)\\.out",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Output was written to a logging handler, a subprocess, or a C-level fd, none of which capsys captures. capsys only captures Python-level sys.stdout/stderr writes.",
  "root_cause_type": "generic",
  "root_cause_zh": "输出写入了日志处理器、子进程或 C 层文件描述符，这些 capsys 都无法捕获。capsys 仅捕获 Python 层的 sys.stdout/stderr 写入。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Each call drains the buffer; repeated calls return empty strings after the first.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "That disables capture entirely; the assertion still sees nothing.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "def test_cli(capfd):\n    import subprocess, sys\n    subprocess.run([sys.executable, \"-c\", \"print('hello')\"])\n    out, err = capfd.readouterr()\n    assert out == \"hello\\n\"",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.94,
      "how": "import logging\n\ndef test_log(caplog):\n    with caplog.at_level(logging.INFO):\n        logging.getLogger(\"app\").info(\"hello\")\n    assert \"hello\" 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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}