{
  "id": "python/pytest-monkeypatch-attribute-not-exist",
  "signature": "AttributeError: 'module' object has no attribute 'some_func'",
  "signature_zh": "属性错误：'module' 对象没有属性 'some_func'",
  "regex": "AttributeError:\\ 'module'\\ object\\ has\\ no\\ attribute\\ 'some_func'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "使用 monkeypatch 尝试修补不存在的属性，通常因为拼写错误或模块路径错误。",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 monkeypatch 尝试修补不存在的属性，通常因为拼写错误或模块路径错误。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "使用 setattr 而不是 monkeypatch.setattr",
      "why_fails": "尝试使用 setattr 直接设置属性，但 monkeypatch 的上下文管理器自动恢复会失败",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "修补错误的模块路径",
      "why_fails": "尝试修补模块的 __init__.py 中的函数，但实际函数定义在子模块中",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "使用正确的完整路径",
      "success_rate": 0.9,
      "how": "monkeypatch.setattr('module.submodule.func', lambda: 42)",
      "condition": "",
      "sources": []
    },
    {
      "action": "先导入模块对象再修补",
      "success_rate": 0.95,
      "how": "import module\nmonkeypatch.setattr(module, 'func', lambda: 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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}