{
  "id": "python/unittest-testcase-requires-method",
  "signature": "TypeError: TestCase.__init__() missing 1 required positional argument: 'methodName'",
  "signature_zh": "TypeError: TestCase.__init__() 缺少 1 个必需的位置参数: 'methodName'",
  "regex": "TypeError:\\ TestCase\\.__init__\\(\\)\\ missing\\ 1\\ required\\ positional\\ argument:\\ 'methodName'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Instantiating a `unittest.TestCase` subclass directly (e.g. `MyTest()`) instead of letting the test runner instantiate it, or forgetting to pass a method name.",
  "root_cause_type": "generic",
  "root_cause_zh": "直接实例化 `unittest.TestCase` 子类（如 `MyTest()`），而不是让测试运行器实例化，或忘记传入方法名。",
  "versions": [
    {
      "version": "3.9",
      "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": "Creates an invalid test case that fails later at run time with a different error.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Still raises because TestCase requires methodName.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Use the test runner instead of instantiating directly:\nimport unittest\nunittest.main()\n# or\nloader = unittest.TestLoader()\nsuite = loader.loadTestsFromTestCase(MyTest)\nunittest.TextTestRunner().run(suite)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "If you must instantiate: `case = MyTest('test_something')` then `case.run(result)`.",
      "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": "2024-04-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}