{
  "id": "python/unittest-testcase-not-iterable",
  "signature": "TypeError: 'TestSuite' object is not iterable",
  "signature_zh": "TypeError: 'TestSuite' 对象不可迭代",
  "regex": "TypeError:\\ 'TestSuite'\\ object\\ is\\ not\\ iterable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Code tries to iterate over a unittest.TestSuite directly (e.g. for t in suite), but TestSuite is not iterable in the way expected; tests must be accessed via suite._tests or by using a TestLoader/TextTestRunner.",
  "root_cause_type": "generic",
  "root_cause_zh": "代码试图直接遍历 unittest.TestSuite（如 for t in suite），但 TestSuite 并不按预期方式可迭代；测试需通过 suite._tests 访问或使用 TestLoader/TextTestRunner。",
  "versions": [
    {
      "version": "3.8",
      "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": "TestSuite does not implement __iter__, so list() raises the same TypeError.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "run() executes tests and returns a TestResult, not an iterable of tests.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use the loader to discover tests and iterate the returned suite's _tests, or use unittest's runner:\n\nloader = unittest.TestLoader()\nsuite = loader.discover('tests')\nresult = unittest.TextTestRunner(verbosity=2).run(suite)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Access the internal list when needed (with care):\n\nfor test in suite._tests:\n    print(test)",
      "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-03-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}