{
  "id": "python/pytest-scope-mismatch-session-function",
  "signature": "ScopeMismatch: You tried to access the function scoped fixture 'tmp_path' with a session scoped request object",
  "signature_zh": "ScopeMismatch: 你尝试用 session 作用域的请求对象访问 function 作用域的 fixture 'tmp_path'",
  "regex": "ScopeMismatch:\\ You\\ tried\\ to\\ access\\ the\\ function\\ scoped\\ fixture\\ 'tmp_path'\\ with\\ a\\ session\\ scoped\\ request\\ object",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A higher-scoped fixture (session/module) depends on a lower-scoped fixture (function), which pytest forbids because the lower-scoped fixture would need to be recreated per test.",
  "root_cause_type": "generic",
  "root_cause_zh": "较高作用域的 fixture（session/module）依赖较低作用域的 fixture（function），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 raised by pytest during fixture resolution before the body runs; catching it inside the fixture never executes.",
      "fail_rate": 0.98,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "autouse changes when fixtures are requested, not their scope, so the ScopeMismatch persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "No such option exists; pytest ignores unknown ini keys and the error remains.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "# Instead of session-scoped fixture depending on tmp_path:\n@pytest.fixture\ndef db(tmp_path):\n    ...\n\n@pytest.fixture(scope=\"session\")\ndef db_session():\n    import tempfile\n    with tempfile.TemporaryDirectory() as d:\n        yield make_db(d)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.75,
      "how": "@pytest.fixture(scope=\"session\")\ndef heavy(request):\n    def get_tmp():\n        return request.getfixturevalue(\"tmp_path\")\n    yield get_tmp",
      "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-05-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}