{
  "id": "python/pytest-fixture-scope-mismatch",
  "signature": "ScopeMismatch: You tried to access the 'session' scoped fixture 'db_connection' from a 'function' scoped fixture 'user_fixture'",
  "signature_zh": "ScopeMismatch: 你尝试从 'function' 作用域的 fixture 'user_fixture' 访问 'session' 作用域的 fixture 'db_connection'",
  "regex": "ScopeMismatch:\\ You\\ tried\\ to\\ access\\ the\\ 'session'\\ scoped\\ fixture\\ 'db_connection'\\ from\\ a\\ 'function'\\ scoped\\ fixture\\ 'user_fixture'",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A fixture with a narrower scope tries to depend on a fixture with a broader scope, which is not allowed in pytest.",
  "root_cause_type": "generic",
  "root_cause_zh": "一个具有较窄作用域的 fixture 尝试依赖一个具有较宽作用域的 fixture，这在 pytest 中是不允许的。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This may cause resource leaks or unintended sharing of state across tests, leading to test pollution.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This bypasses the scope check but still violates the intended dependency hierarchy, potentially causing runtime errors.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Restructure fixtures so that the broader-scoped fixture is used directly in tests, not via a narrower fixture.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Change the scope of the dependent fixture to 'session' if appropriate: `@pytest.fixture(scope='session')\ndef user_fixture(db_connection):`",
      "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-06-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}