{
  "id": "python/unittest-buffer-stdout-lost",
  "signature": "test_output (tests.test_cli.TestCli) ... ok\n\n(no captured stdout shown despite print() in the test)",
  "signature_zh": "test_output (tests.test_cli.TestCli) ... ok\n\n（尽管测试中有 print()，但没有显示捕获的 stdout）",
  "regex": "test_output\\ \\(tests\\.test_cli\\.TestCli\\)\\ \\.\\.\\.\\ ok\\\n\\\n\\(no\\ captured\\ stdout\\ shown\\ despite\\ print\\(\\)\\ in\\ the\\ test\\)",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "unittest's buffer mode (`python -m unittest -b`) captures stdout/stderr and only prints it on failure; passing tests show nothing, so debugging prints are invisible.",
  "root_cause_type": "generic",
  "root_cause_zh": "unittest 的缓冲模式（`python -m unittest -b`）捕获 stdout/stderr 且仅在失败时打印；通过的测试不显示任何内容，调试打印不可见。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "stderr is also captured by buffer mode; still hidden on pass.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Turns the test red; not usable for debugging passing tests.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Disable buffering for the run:\npython -m unittest -v tests.test_cli.TestCli\n# or remove -b from the command / CI config",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Or capture stdout explicitly with contextlib.redirect_stdout:\nimport io, contextlib\nbuf = io.StringIO()\nwith contextlib.redirect_stdout(buf):\n    run_cli(['--help'])\nself.assertIn('usage', buf.getvalue())",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}