{
  "id": "python/unittest-mock-return-value-attribute",
  "signature": "AttributeError: 'function' object has no attribute 'return_value'",
  "signature_zh": "属性错误：'function' 对象没有属性 'return_value'",
  "regex": "AttributeError:\\ 'function'\\ object\\ has\\ no\\ attribute\\ 'return_value'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Trying to set return_value on a regular function instead of a Mock object, often because the patch decorator was not applied correctly or the target is not a mock.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试在常规函数上设置 return_value，而不是在 Mock 对象上，通常是因为 patch 装饰器未正确应用或目标不是模拟对象。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Wrapping the function in a Mock manually may work but bypasses the patch mechanism and can cause test isolation issues.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using patch.object with a string instead of the actual object may still fail if the attribute does not exist.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Ensure the patch decorator is applied to the test function: @patch('module.function') def test(mock_func): mock_func.return_value = 42",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Use patch as a context manager: with patch('module.function') as mock_func: mock_func.return_value = 42",
      "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": "2025-06-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}