{
  "id": "python/unittest-subtest-failure",
  "signature": "AssertionError: 2 != 3 during subTest (index=0)",
  "signature_zh": "断言错误：在子测试（index=0）中 2 != 3",
  "regex": "AssertionError:\\ 2\\ !=\\ 3\\ during\\ subTest\\ \\(index=0\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A subTest context manager failed due to an assertion error, indicating that one iteration of a looped test failed while others may pass.",
  "root_cause_type": "generic",
  "root_cause_zh": "subTest上下文管理器因断言错误而失败，表明循环测试的一次迭代失败，而其他迭代可能通过。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Removing the subTest context to run all iterations as separate tests",
      "why_fails": "This changes the test structure and may not capture the context of the failure.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increasing the number of iterations to avoid the specific failing case",
      "why_fails": "This masks the bug; the failing case should be fixed.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Debug the specific subTest iteration that fails",
      "success_rate": 0.9,
      "how": "for i, value in enumerate(data):\n    with self.subTest(i=i):\n        self.assertEqual(value, expected[i])\nIf it fails, check the value and expected at index i.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a more descriptive subTest message to identify the failing case",
      "success_rate": 0.85,
      "how": "with self.subTest(i=i, value=value):\n    self.assertEqual(value, expected[i])\nThis provides more context in the error message.",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-09-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}