{
  "id": "python/pytest-session-fixture-scope-mismatch",
  "signature": "ScopeMismatch: You tried to access the function scoped fixture db_session with a session scoped request object",
  "signature_zh": "ScopeMismatch: 你试图在会话作用域的请求对象中访问函数作用域的 fixture db_session",
  "regex": "ScopeMismatch:\\ You\\ tried\\ to\\ access\\ the\\ function\\ scoped\\ fixture\\ db_session\\ with\\ a\\ session\\ scoped\\ request\\ object",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A session-scoped fixture depends on a function-scoped fixture, which pytest forbids because the shorter-lived fixture cannot outlive its scope.",
  "root_cause_type": "generic",
  "root_cause_zh": "会话作用域的 fixture 依赖函数作用域的 fixture，pytest 禁止这样做，因为生命周期较短的 fixture 无法存活于其作用域之外。",
  "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 error is about the fixture dependency graph, not the test; the mismatch persists.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Autouse does not change scope; the ScopeMismatch still occurs.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Align the dependent fixture's scope to session, or restructure so the session fixture does not depend on a function fixture:\n\n@pytest.fixture(scope='session')\ndef engine():\n    ...\n\n@pytest.fixture\ndef db_session(engine):\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Use a factory fixture to create per-test objects from a session resource.",
      "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-09-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}