{
  "id": "python/unittest-mock-side-effect-not-raised",
  "signature": "AssertionError: ValueError not raised\nDuring handling of the above exception, another exception occurred:\nTypeError: 'ValueError' object is not callable",
  "signature_zh": "AssertionError: 未抛出 ValueError\n在处理上述异常时，又发生了一个异常:\nTypeError: 'ValueError' 对象不可调用",
  "regex": "AssertionError:\\ ValueError\\ not\\ raised\\\nDuring\\ handling\\ of\\ the\\ above\\ exception,\\ another\\ exception\\ occurred:\\\nTypeError:\\ 'ValueError'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "mock.side_effect was set to an exception instance instead of the exception class; mock tries to call the instance and raises TypeError instead of the intended exception.",
  "root_cause_type": "generic",
  "root_cause_zh": "mock.side_effect 被设置为异常实例而不是异常类；mock 尝试调用该实例并抛出 TypeError，而非预期的异常。",
  "versions": [
    {
      "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": "return_value returns the exception object as the call result; it is never raised, so the test still fails.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Masks the mock misconfiguration and makes the test pass for the wrong reason; the SUT never actually raised.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.96,
      "how": "from unittest import mock\n\nwith mock.patch('myapp.fetch') as m:\n    m.side_effect = ValueError  # class, not ValueError()\n    with pytest.raises(ValueError):\n        call_sut()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.94,
      "how": "def boom(*args, **kwargs):\n    raise ValueError('bad input')\n\nwith mock.patch('myapp.fetch', side_effect=boom):\n    with pytest.raises(ValueError, match='bad input'):\n        call_sut()",
      "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-02-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}