{
  "id": "python/unittest-assertraises-context-manager",
  "signature": "AssertionError: ValueError not raised when calling func()",
  "signature_zh": "断言错误：调用 func() 时未引发 ValueError",
  "regex": "AssertionError:\\ ValueError\\ not\\ raised\\ when\\ calling\\ func\\(\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The test uses assertRaises but the code under test does not raise the expected exception, either due to a bug in the code or incorrect test setup.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试使用了 assertRaises，但被测试代码没有引发预期的异常，可能是由于代码中的错误或测试设置不正确。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Wrapping the call in a try-except block and manually asserting may mask other issues like incorrect exception types.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the expected exception to a broader type (e.g., Exception) works but reduces test specificity and may hide bugs.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Debug the code under test to ensure it raises the exception under the given conditions. For example, check input validation logic.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use assertRaises with a lambda or callable: self.assertRaises(ValueError, func, arg) to ensure the exception is raised during the call.",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}