{
  "id": "python/pytest-subtests-plugin-missing",
  "signature": "AttributeError: 'TestCaseFunction' object has no attribute 'subTest'",
  "signature_zh": "AttributeError: 'TestCaseFunction' 对象没有属性 'subTest'",
  "regex": "AttributeError:\\ 'TestCaseFunction'\\ object\\ has\\ no\\ attribute\\ 'subTest'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "self.subTest() is a unittest.TestCase method. Calling it on a pytest-style test class or a plain function that doesn't inherit from unittest.TestCase raises AttributeError.",
  "root_cause_type": "generic",
  "root_cause_zh": "self.subTest() 是 unittest.TestCase 的方法。在 pytest 风格的测试类或未继承 unittest.TestCase 的普通函数上调用会抛出 AttributeError。",
  "versions": [
    {
      "version": "3.11",
      "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": "pytest-subtests adds support for TestCase.subTest in pytest-style classes only if the class inherits TestCase; a plain class still lacks the method.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Fragile; the semantics of subTest (reporting multiple failures per test) aren't replicated by a naive patch.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "import unittest\nimport pytest\n\nclass TestMath(unittest.TestCase):\n    def test_add(self):\n        for a, b, exp in [(1,2,3),(2,3,5)]:\n            with self.subTest(a=a, b=b):\n                self.assertEqual(a+b, exp)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.94,
      "how": "@pytest.mark.parametrize('a,b,exp', [(1,2,3),(2,3,5)])\ndef test_add(a, b, exp):\n    assert a + b == exp",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-04-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}