{
  "id": "python/pytest-session-fixture-mutation-leak",
  "signature": "AssertionError: assert 5 == 3\n# but passes when run individually: pytest tests/test_counter.py::test_reset passes",
  "signature_zh": "AssertionError: assert 5 == 3\n# 但单独运行时通过: pytest tests/test_counter.py::test_reset 通过",
  "regex": "AssertionError:\\ assert\\ 5\\ ==\\ 3\\\n\\#\\ but\\ passes\\ when\\ run\\ individually:\\ pytest\\ tests/test_counter\\.py::test_reset\\ passes",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "A session-scoped fixture holds mutable state that a previous test mutated; test order dependence makes it pass in isolation but fail in the full run.",
  "root_cause_type": "generic",
  "root_cause_zh": "session 作用域的 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": "May make the suite pass by accident on one order, but the underlying shared state bug remains.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Timing is not the issue; state leakage is. The failure persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture\ndef counter():\n    return Counter()  # function scope, fresh each test\n\n# or use a factory:\n@pytest.fixture\ndef make_counter():\n    def _make():\n        return Counter()\n    return _make",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "@pytest.fixture(autouse=True)\ndef reset_state():\n    yield\n    global_state.clear()",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-12-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}