{
  "id": "python/pytest-randomly-fails-order-dependent",
  "signature": "FAILED tests/test_state.py::test_b - AssertionError: assert [] == [1, 2]\n# passes when run alone, fails when run after test_a",
  "signature_zh": "FAILED tests/test_state.py::test_b - AssertionError: assert [] == [1, 2]\n# 单独运行通过，在 test_a 之后运行则失败",
  "regex": "FAILED\\ tests/test_state\\.py::test_b\\ \\-\\ AssertionError:\\ assert\\ \\[\\]\\ ==\\ \\[1,\\ 2\\]\\\n\\#\\ passes\\ when\\ run\\ alone,\\ fails\\ when\\ run\\ after\\ test_a",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "pytest-randomly shuffles test order and exposes shared mutable state (module-level list, class attribute, or global cache) that leaks between tests.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-randomly 打乱测试顺序，暴露了模块级列表、类属性或全局缓存等共享可变状态在测试之间泄漏的问题。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Hides the state leak; the bug returns in production or when order changes in CI.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Reproduces the same order but does not fix the leaking state.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "import pytest\n\n@pytest.fixture(autouse=True)\ndef reset_state():\n    import myapp.cache\n    myapp.cache.clear()\n    yield\n    myapp.cache.clear()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "@pytest.fixture\ndef items():\n    return []\n\ndef test_a(items):\n    items.append(1)\n\ndef test_b(items):\n    assert items == []  # always fresh",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}