{
  "id": "python/pytest-fixture-return-generator",
  "signature": "TypeError: 'generator' object is not callable",
  "signature_zh": "类型错误：'generator' 对象不可调用",
  "regex": "TypeError:\\ 'generator'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "在 pytest fixture 中使用了 yield 但忘记添加 @pytest.fixture 装饰器，导致生成器对象被当作函数调用。",
  "root_cause_type": "generic",
  "root_cause_zh": "在 pytest fixture 中使用了 yield 但忘记添加 @pytest.fixture 装饰器，导致生成器对象被当作函数调用。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "将 yield 改为 return，忽略 teardown",
      "why_fails": "尝试将 fixture 改为普通函数并直接 return，但 fixture 需要 teardown 逻辑，导致资源泄漏",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "在测试函数中直接调用 fixture 名称",
      "why_fails": "在测试函数中直接调用 fixture 名称而不加括号，但 fixture 是生成器，无法被直接调用",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "添加 @pytest.fixture 装饰器",
      "success_rate": 0.95,
      "how": "@pytest.fixture\ndef my_fixture():\n    yield 42",
      "condition": "",
      "sources": []
    },
    {
      "action": "在测试函数参数中接收 fixture",
      "success_rate": 0.9,
      "how": "def test_func(my_fixture):\n    assert my_fixture == 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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}