{
  "id": "python/pytest-mock-patch-not-applied",
  "signature": "AssertionError: Expected 'mock_method' to have been called once. Called 0 times.",
  "signature_zh": "AssertionError: 期望 'mock_method' 被调用一次。实际调用 0 次。",
  "regex": "AssertionError:\\ Expected\\ 'mock_method'\\ to\\ have\\ been\\ called\\ once\\.\\ Called\\ 0\\ times\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The mock was applied to the wrong namespace or the code under test imports the function directly, bypassing the patch.",
  "root_cause_type": "generic",
  "root_cause_zh": "mock 应用到了错误的命名空间，或被测代码直接导入函数，绕过了 patch。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The test then passes but does not verify the intended behavior; the mock is still not applied.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the target is incorrect, patch.object fails similarly.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "If my_module.py does 'from other_module import my_func', patch 'my_module.my_func' instead of 'other_module.my_func'.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def test_my_func(monkeypatch):\n    monkeypatch.setattr('my_module.my_func', lambda: None)\n    # test code",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "import my_module; print(my_module.my_func.__module__) to see where it's defined, then patch accordingly.",
      "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-07-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}