{
  "id": "python/unittest-assertraises-not-raised",
  "signature": "AssertionError: ValueError not raised",
  "signature_zh": "AssertionError: 未引发 ValueError",
  "regex": "AssertionError:\\ ValueError\\ not\\ raised",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The code under test does not raise the expected exception, or the exception is caught inside the function, or the test is not actually executing the code that should raise.",
  "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": "This duplicates assertRaises and often leads to false positives if the exception is caught.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The underlying issue is that the exception is not raised, so switching frameworks won't help.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Add print statements before the call to ensure it's reached. Use pdb.set_trace() to step through. Check if the function has a try/except that swallows the error.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "with self.assertRaises(ValueError) as cm:\n    my_func()\nprint(cm.exception)  # see if any exception was raised",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}