{
  "id": "python/unittest-assertraises-no-exception",
  "signature": "AssertionError: ValueError not raised",
  "signature_zh": "AssertionError: 未引发 ValueError",
  "regex": "AssertionError:\\ ValueError\\ not\\ raised",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "self.assertRaises(ValueError) was used as a context manager but the code under test did not raise, or the exception was caught and swallowed inside the function.",
  "root_cause_type": "generic",
  "root_cause_zh": "self.assertRaises(ValueError) 作为上下文管理器使用，但被测代码未引发异常，或异常在函数内部被捕获并吞掉。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "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": "Inverts the logic: except catches the expected exception and calls fail, so a correct raise now fails the test.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Broadens the assertion so much that any unrelated error (e.g. TypeError) passes the test, masking real bugs.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "with self.assertRaises(ValueError) as ctx:\n    parse('bad-input')\nself.assertIn('bad-input', str(ctx.exception))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "import pytest\n\ndef test_parse_raises():\n    with pytest.raises(ValueError, match=r'bad-input'):\n        parse('bad-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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}