{
  "id": "python/pytest-subtests-not-counted",
  "signature": "FAILED tests/test_math.py::test_ops - AssertionError: 1 != 2",
  "signature_zh": "FAILED tests/test_math.py::test_ops - AssertionError: 1 != 2",
  "regex": "FAILED\\ tests/test_math\\.py::test_ops\\ \\-\\ AssertionError:\\ 1\\ !=\\ 2",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "When using `self.subTest(...)` inside a unittest.TestCase, subtests do not stop the parent test from continuing, but the parent still reports as FAILED. Developers expect each subtest to appear as a separate test case.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 unittest.TestCase 内使用 `self.subTest(...)` 时，子测试不会阻止父测试继续执行，但父测试仍报告为 FAILED。开发者期望每个子测试作为独立的测试用例出现。",
  "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": "Loses the loop-based data-driven style; verbose but works, so it is not really a dead end—more of a workaround.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Raises immediately, aborting remaining subtests and defeating the purpose of subTest.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "Use pytest's parametrize instead for per-case reporting:\n\nimport pytest\n\n@pytest.mark.parametrize('a,b,expected', [(1,1,2),(2,2,4)])\ndef test_add(a, b, expected):\n    assert a + b == expected",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Install pytest-subtests to surface each subTest as its own result:\n\npip install pytest-subtests\n\n# now each subTest failure is reported individually",
      "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": "2025-05-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}