{
  "id": "python/pytest-subtest-in-pytest",
  "signature": "AttributeError: 'TestCase' object has no attribute 'subTest'",
  "signature_zh": "AttributeError：'TestCase' 对象没有属性 'subTest'",
  "regex": "AttributeError:\\ 'TestCase'\\ object\\ has\\ no\\ attribute\\ 'subTest'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A unittest.TestCase test using self.subTest was collected by pytest but the class doesn't inherit from unittest.TestCase, or the wrong base class was imported (e.g., pytest.TestCase doesn't exist).",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 self.subTest 的 unittest.TestCase 测试被 pytest 收集，但该类没有继承自 unittest.TestCase，或导入了错误的基类（例如 pytest.TestCase 不存在）。",
  "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": "Plugin helps pytest-side subtest support, but missing TestCase inheritance is the real issue.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses per-case reporting and stops at first failure.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Masks the class hierarchy bug.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "import unittest\n\nclass TestMath(unittest.TestCase):\n    def test_add(self):\n        for a, b, expected in [(1,1,2),(2,2,4)]:\n            with self.subTest(a=a, b=b):\n                self.assertEqual(a+b, expected)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "pip install pytest-subtests\n# then use pytest.mark.parametrize instead of subTest",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-02-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}