{
  "id": "python/pytest-fixture-setup-error",
  "signature": "pytest.fixture: error in fixture 'db_connection' during setup",
  "signature_zh": "pytest.fixture: 在设置期间夹具'db_connection'出错",
  "regex": "pytest\\.fixture:\\ error\\ in\\ fixture\\ 'db_connection'\\ during\\ setup",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The fixture function raised an exception during setup phase, before the test function could execute. This commonly occurs when the fixture performs I/O operations (database connections, file reads, network calls) that fail.",
  "root_cause_type": "generic",
  "root_cause_zh": "夹具函数在设置阶段（测试函数执行前）抛出异常。这通常发生在夹具执行I/O操作（数据库连接、文件读取、网络调用）失败时。",
  "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": "The decorator only ensures the fixture runs, it does not handle exceptions raised during fixture setup. The underlying error remains unaddressed.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The exception occurs during fixture setup, before the test function body executes, so the try/except inside the test never catches it.",
      "fail_rate": 0.92,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.88,
      "how": "@pytest.fixture\ndef db_connection():\n    conn = None\n    try:\n        conn = create_connection()\n        yield conn\n    except Exception as e:\n        pytest.fail(f'DB setup failed: {e}')\n    finally:\n        if conn:\n            conn.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.82,
      "how": "@pytest.fixture\ndef db_connection(mocker):\n    return mocker.MagicMock()",
      "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-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}