{
  "id": "python/unittest-assert-raises-no-exception",
  "signature": "AssertionError: ValueError not raised by parse_input",
  "signature_zh": "AssertionError：parse_input 未引发 ValueError",
  "regex": "AssertionError:\\ ValueError\\ not\\ raised\\ by\\ parse_input",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "assertRaises expects the callable to raise the specified exception. If the function returns normally (e.g., it was fixed, or the input is valid), the context manager's __exit__ receives no exception and the test fails.",
  "root_cause_type": "generic",
  "root_cause_zh": "assertRaises 期望可调用对象引发指定的异常。如果函数正常返回（例如它已被修复，或者输入有效），上下文管理器的 __exit__ 不会收到异常，测试就会失败。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "assertRaisesRegex still requires the exception to be raised; an empty pattern matches anything but the exception absence still fails.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Reimplements assertRaises worse; loses the informative 'ValueError not raised' message and complicates the test.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "def parse_input(s):\n    if not s:\n        raise ValueError('empty input')\n    return int(s)\n\n# test\nwith self.assertRaises(ValueError):\n    parse_input('')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.96,
      "how": "import pytest\n\ndef test_parse_input_empty():\n    with pytest.raises(ValueError, match='empty input'):\n        parse_input('')",
      "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-01-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}