{
  "id": "python/unittest-assertraises-not-called",
  "signature": "TypeError: assertRaises() missing 1 required positional argument: 'callable'",
  "signature_zh": "TypeError: assertRaises() 缺少 1 个必需的位置参数：'callable'",
  "regex": "TypeError:\\ assertRaises\\(\\)\\ missing\\ 1\\ required\\ positional\\ argument:\\ 'callable'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "unittest.TestCase.assertRaises can be used as a context manager or called with a callable plus args. Calling it with only an exception class and no callable (or not using `with`) raises TypeError.",
  "root_cause_type": "generic",
  "root_cause_zh": "unittest.TestCase.assertRaises 既可用作上下文管理器，也可传入可调用对象和参数。仅传入异常类而不传可调用对象（或未使用 `with`）会引发 TypeError。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "assertRaises expects an exception class or tuple of classes, not a string; passing a string causes a different TypeError about the expected type.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This actually works, but if the user forgets the second argument entirely (the common mistake), it still raises the same TypeError; the dead-end is the mental model of 'just add the exception class'.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "with self.assertRaises(ValueError):\n    int('not-a-number')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "self.assertRaises(ValueError, int, 'not-a-number')\n# or with keyword args:\nself.assertRaises(ValueError, int, base=2, x='zz')",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}