{
  "id": "python/pytest-monkeypatch-setattr-class",
  "signature": "AttributeError: <class 'mypkg.Client'> has no attribute 'endpoint'",
  "signature_zh": "AttributeError: <class 'mypkg.Client'> 没有属性 'endpoint'",
  "regex": "AttributeError:\\ <class\\ 'mypkg\\.Client'>\\ has\\ no\\ attribute\\ 'endpoint'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "monkeypatch.setattr(Client, 'endpoint', ...) requires the attribute to already exist unless raising=False is passed; monkeypatch deliberately refuses to create new attributes.",
  "root_cause_type": "generic",
  "root_cause_zh": "monkeypatch.setattr(Client, 'endpoint', ...) 要求属性已存在，除非传入 raising=False；monkeypatch 有意拒绝创建新属性。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Bypasses monkeypatch's automatic undo; the attribute leaks into subsequent tests.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The code under test instantiates the original Client, not the subclass, so the override has no effect.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_client(monkeypatch):\n    monkeypatch.setattr(Client, 'endpoint', 'http://test', raising=False)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "client = Client()\nmonkeypatch.setattr(client, 'endpoint', 'http://test')",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-18",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}