{
  "id": "python/unittest-assert-raises-not-caught",
  "signature": "AssertionError: ValueError not raised by my_function",
  "signature_zh": "AssertionError: my_function 未引发 ValueError",
  "regex": "AssertionError:\\ ValueError\\ not\\ raised\\ by\\ my_function",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The function under test does not raise the expected exception, or the exception is caught inside the function and not re-raised.",
  "root_cause_type": "generic",
  "root_cause_zh": "被测函数未引发预期的异常，或者异常在函数内部被捕获且未重新引发。",
  "versions": [
    {
      "version": "3.8",
      "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": "Tests the test, not the function; false positive.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Too broad; may pass for unrelated exceptions and hide bugs.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def my_function(x):\n    if x < 0:\n        raise ValueError('negative')\n    return x\n\nwith self.assertRaises(ValueError):\n    my_function(-1)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "with pytest.raises(ValueError, match='negative'):\n    my_function(-1)",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}