{
  "id": "python/pytest-collection-fixture-not-found",
  "signature": "E       fixture 'db_connection' not found",
  "signature_zh": "E       fixture 'db_connection' 未找到",
  "regex": "E\\ \\ \\ \\ \\ \\ \\ fixture\\ 'db_connection'\\ not\\ found",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "pytest cannot locate a fixture referenced by a test. The fixture is either defined in a conftest.py outside the test's rootdir, misspelled, not imported, or scoped to a directory pytest isn't collecting.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest 无法找到测试引用的 fixture。该 fixture 可能定义在测试 rootdir 之外的 conftest.py 中、拼写错误、未导入，或作用域限于 pytest 未收集的目录。",
  "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": "Duplicates fixture logic across files, and if the fixture depends on session-scoped resources (DB, network), local copies break isolation and teardown.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "PYTHONPATH affects import resolution, not pytest fixture discovery. conftest.py is discovered by walking up from rootdir, not via sys.path.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "# conftest.py at project root\nimport pytest\n@pytest.fixture\ndef db_connection():\n    conn = create_conn()\n    yield conn\n    conn.close()\n\n# tests/test_x.py\ndef test_query(db_connection):\n    assert db_connection.execute('SELECT 1').fetchone()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "# tests/conftest.py\npytest_plugins = ['myapp.testing.fixtures']\n\n# run with explicit rootdir\n# pytest --rootdir=. tests/",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.78,
      "how": "pytest --fixtures -q | grep db_connection\n# If missing, check conftest.py location and rootdir:\npytest --collect-only -q",
      "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-03-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}