{
  "id": "python/unittest-mock-patch-import-error",
  "signature": "ImportError: No module named 'module_to_patch'",
  "signature_zh": "ImportError: 没有名为 'module_to_patch' 的模块",
  "regex": "ImportError:\\ No\\ module\\ named\\ 'module_to_patch'",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "The `@unittest.mock.patch('module_to_patch.ClassName')` decorator tries to patch a module that does not exist or is not importable.",
  "root_cause_type": "generic",
  "root_cause_zh": "`@unittest.mock.patch('module_to_patch.ClassName')` 装饰器尝试修补一个不存在或不可导入的模块。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "The module might be an internal part of the codebase that should be patched differently.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Decorators are evaluated at import time; try-except cannot catch import errors in this context.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Ensure the module path is correct: `@patch('my_package.module_to_patch.ClassName')`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use patch.object() with the actual class: `@patch.object(MyClass, 'method_name')`",
      "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-07-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}