{
  "id": "python/unittest-mock-patch-import-order",
  "signature": "TypeError: cannot mock attribute 'requests' of 'module' object; use patch.object() instead",
  "signature_zh": "类型错误：无法模拟 'module' 对象的属性 'requests'；请改用 patch.object()",
  "regex": "TypeError:\\ cannot\\ mock\\ attribute\\ 'requests'\\ of\\ 'module'\\ object;\\ use\\ patch\\.object\\(\\)\\ instead",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Using @patch('module.requests') when 'requests' is a module-level import and not an attribute of the module object, often due to import order or namespace issues.",
  "root_cause_type": "generic",
  "root_cause_zh": "当 'requests' 是模块级导入而不是模块对象的属性时，使用 @patch('module.requests')，通常是由于导入顺序或命名空间问题。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Changing the import to 'from module import requests' and patching 'module.requests' may still fail if the import is inside a function.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using patch('requests') instead of 'module.requests' patches the global requests module, which may affect other tests.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use patch.object(module, 'requests') to mock the attribute directly on the module object.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Patch the module where it is used: e.g., patch('module.requests.get') if you want to mock a specific method.",
      "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": "2025-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}