{
  "id": "python/pytest-fixture-scope-collision",
  "signature": "ScopeError: fixture 'db' defined in conftest.py conflicts with fixture 'db' defined in test_module.py",
  "signature_zh": "作用域错误：conftest.py 中定义的夹具 'db' 与 test_module.py 中定义的夹具 'db' 冲突",
  "regex": "ScopeError:\\ fixture\\ 'db'\\ defined\\ in\\ conftest\\.py\\ conflicts\\ with\\ fixture\\ 'db'\\ defined\\ in\\ test_module\\.py",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "同一夹具名称在 conftest.py 和测试模块中重复定义，pytest 无法确定使用哪个夹具，导致作用域冲突。",
  "root_cause_type": "generic",
  "root_cause_zh": "同一夹具名称在 conftest.py 和测试模块中重复定义，pytest 无法确定使用哪个夹具，导致作用域冲突。",
  "versions": [
    {
      "version": "7.4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "如果 conftest.py 中的夹具被其他测试文件使用，删除会导致其他测试失败。",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "重命名后，测试函数中的引用需要同步修改，容易遗漏，且不解决根本冲突。",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "在 conftest.py 中定义通用夹具，在测试模块中定义专用夹具，并确保名称唯一。例如：conftest.py 中定义 'db_global'，测试模块中定义 'db_local'。",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.7,
      "how": "将 conftest.py 中的夹具设为可覆盖，测试模块中定义同名夹具时，pytest 会优先使用测试模块中的。但需确保 conftest.py 中夹具不需要被其他测试使用。",
      "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": []
}