{
  "id": "python/pytest-capsys-no-output",
  "signature": "AssertionError: assert 'hello' in ''\n  where '' = capsys.readouterr().out",
  "signature_zh": "AssertionError: assert 'hello' in ''\n  其中 '' = capsys.readouterr().out",
  "regex": "AssertionError:\\ assert\\ 'hello'\\ in\\ ''\\\n\\ \\ where\\ ''\\ =\\ capsys\\.readouterr\\(\\)\\.out",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "capsys only captures sys.stdout/sys.stderr writes. Code that uses logging, os.write(1, ...), or a C extension writing to fd 1 bypasses Python's sys.stdout and is not captured.",
  "root_cause_type": "generic",
  "root_cause_zh": "capsys 仅捕获通过 sys.stdout/sys.stderr 的写入。使用 logging、os.write(1, ...) 或 C 扩展直接写文件描述符 1 的代码会绕过 sys.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": "readouterr() drains the buffer; the second call returns empty strings.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Mixing fixtures means output goes to the fd-level buffer while the test reads the sys-level buffer.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use caplog for logging output:\n\ndef test_log(caplog):\n    logging.getLogger(__name__).warning('hello')\n    assert 'hello' in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Use capfd for file-descriptor-level output:\n\ndef test_fd(capfd):\n    os.write(1, b'hello')\n    out, err = capfd.readouterr()\n    assert 'hello' in out",
      "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-07-21",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}