{
  "id": "python/pytest-random-order-flaky",
  "signature": "FAILED tests/test_state.py::test_reads_cache - KeyError: 'user:1'\n\n(Passes with `pytest -p no:randomly`, fails with random order)",
  "signature_zh": "FAILED tests/test_state.py::test_reads_cache - KeyError: 'user:1'\n\n（使用 `pytest -p no:randomly` 通过，随机顺序失败）",
  "regex": "FAILED\\ tests/test_state\\.py::test_reads_cache\\ \\-\\ KeyError:\\ 'user:1'\\\n\\\n\\(Passes\\ with\\ `pytest\\ \\-p\\ no:randomly`,\\ fails\\ with\\ random\\ order\\)",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "pytest-randomly shuffles test order each run; a test depends on state created by another test (shared cache, module global, DB row), so it fails when it runs first.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-randomly 每次运行打乱测试顺序；某测试依赖其他测试创建的状态（共享缓存、模块全局、数据库行），因此先运行时失败。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "pytest-randomly ignores order markers unless `-p no:randomly` is set; the shuffle still happens.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Makes the order deterministic but still hides the inter-test dependency; a different seed on CI breaks it.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "Make the test self-contained with a fixture that seeds the cache:\n@pytest.fixture\ndef seeded_cache(cache):\n    cache.set('user:1', {'name': 'alice'})\n    return cache\ndef test_reads_cache(seeded_cache):\n    assert seeded_cache.get('user:1')['name'] == 'alice'",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Or reset shared state between tests:\n@pytest.fixture(autouse=True)\ndef clean_cache(cache):\n    cache.flush_all()\n    yield\n    cache.flush_all()",
      "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-11-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}