{
  "id": "python/pytest-capture-stdout-not-shown",
  "signature": "AssertionError: assert '' == 'expected output'\n  - expected output\n  + ",
  "signature_zh": "AssertionError: assert '' == 'expected output'\n  - expected output\n  + ",
  "regex": "AssertionError:\\ assert\\ ''\\ ==\\ 'expected\\ output'\\\n\\ \\ \\-\\ expected\\ output\\\n\\ \\ \\+\\ ",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The test captures stdout via capsys but the code under test writes to a logger or to sys.__stdout__ instead of sys.stdout, or capsys was requested after the output was already flushed. capsys only captures writes through sys.stdout at call time.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试通过 capsys 捕获 stdout，但被测代码写入的是 logger 或 sys.__stdout__ 而非 sys.stdout，或者 capsys 在输出已被刷新后才被请求。capsys 只捕获调用时通过 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": "capsysbinary only changes the encoding of captured bytes; it still won't capture logger output or writes to sys.__stdout__.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Flushing does not redirect output into the capture buffer if the code wrote to a different stream.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "def test_logs(caplog):\n    with caplog.at_level('INFO'):\n        run_task()\n    assert 'expected output' in caplog.text",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def test_prints(capsys):\n    print('expected output')\n    captured = capsys.readouterr()\n    assert captured.out.strip() == 'expected output'",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}