{
  "id": "python/pytest-mock-magicmock-spec-missing",
  "signature": "AttributeError: Mock object has no attribute 'close'\nDuring handling of the above exception, another exception occurred:\nTypeError: object MagicMock can't be used in 'await' expression",
  "signature_zh": "AttributeError: Mock 对象没有属性 'close'\n处理上述异常时又出现另一个异常:\nTypeError: MagicMock 对象不能在 'await' 表达式中使用",
  "regex": "AttributeError:\\ Mock\\ object\\ has\\ no\\ attribute\\ 'close'\\\nDuring\\ handling\\ of\\ the\\ above\\ exception,\\ another\\ exception\\ occurred:\\\nTypeError:\\ object\\ MagicMock\\ can't\\ be\\ used\\ in\\ 'await'\\ expression",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A MagicMock was returned where an async context manager or specific interface was expected. MagicMock auto-creates attributes but its return values are not awaitable; use AsyncMock for coroutines and configure magic methods.",
  "root_cause_type": "generic",
  "root_cause_zh": "MagicMock 被返回，但期望的是异步上下文管理器或特定接口。MagicMock 会自动创建属性，但其返回值不可 await；协程应使用 AsyncMock 并配置魔术方法。",
  "versions": [
    {
      "version": "3.8",
      "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": "Fixes only the first error; await-related TypeError persists for async usage.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Plain Mock does not support __aenter__/__aexit__ or magic methods; more AttributeErrors appear.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "Use AsyncMock for async interfaces:\n  from unittest.mock import AsyncMock\n  mock_client = AsyncMock()\n  mock_client.get.return_value = {'ok': True}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Configure magic methods on MagicMock:\n  m = MagicMock()\n  m.__aenter__ = AsyncMock(return_value=m)\n  m.__aexit__ = AsyncMock(return_value=None)",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}