{
  "id": "python/pytest-monkeypatch-scope-session",
  "signature": "ScopeMismatch: You tried to access the function scoped fixture monkeypatch with a session scoped request object, involved factories",
  "signature_zh": "ScopeMismatch：您尝试使用会话作用域的请求对象访问函数作用域的 fixture monkeypatch，涉及工厂",
  "regex": "ScopeMismatch:\\ You\\ tried\\ to\\ access\\ the\\ function\\ scoped\\ fixture\\ monkeypatch\\ with\\ a\\ session\\ scoped\\ request\\ object,\\ involved\\ factories",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A session-scoped fixture requested monkeypatch (which is function-scoped), violating pytest's scope ordering rules.",
  "root_cause_type": "generic",
  "root_cause_zh": "会话作用域的 fixture 请求了 monkeypatch（函数作用域），违反了 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": "May break expensive setup assumptions and hides the real scope design issue.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Does not change scope mismatch behavior.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Markers do not alter fixture scope rules.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture(scope=\"session\")\ndef config(): return {\"url\": \"http://x\"}\n\n@pytest.fixture\ndef patched(config, monkeypatch):\n    monkeypatch.setitem(config, \"url\", \"http://test\")\n    return config",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@pytest.fixture(scope=\"session\")\ndef patched():\n    with pytest.MonkeyPatch.context() as mp:\n        mp.setenv(\"X\", \"1\")\n        yield",
      "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-04-26",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}