{
  "id": "python/attributeerror-unittest-no-mock",
  "signature": "AttributeError: module 'unittest' has no attribute 'mock'",
  "signature_zh": "属性错误：模块 'unittest' 没有属性 'mock'",
  "regex": "AttributeError:\\ module\\ 'unittest'\\ has\\ no\\ attribute\\ 'mock'",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "In Python 3.2 and earlier, mock is not part of unittest; must import mock separately or use unittest.mock in Python 3.3+.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Python 3.2 及更早版本中，mock 不是 unittest 的一部分；必须单独导入 mock 或在 Python 3.3+ 中使用 unittest.mock。",
  "versions": [
    {
      "version": "3.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Installing mock via pip",
      "why_fails": "mock is available as a backport but not integrated into unittest; import path is different.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using unittest.mock without importing",
      "why_fails": "If Python version is < 3.3, unittest.mock does not exist.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Import mock from unittest for Python 3.3+",
      "success_rate": 0.95,
      "how": "from unittest.mock import Mock, patch",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use backport mock for older Python",
      "success_rate": 0.9,
      "how": "pip install mock; then from mock import Mock, patch",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}