{
  "id": "python/pytest-test-ordering-random-seed",
  "signature": "AssertionError: assert 0 == 1\n# fails with pytest-randomly, passes with -p no:randomly",
  "signature_zh": "AssertionError: assert 0 == 1\n# 使用 pytest-randomly 时失败，使用 -p no:randomly 时通过",
  "regex": "AssertionError:\\ assert\\ 0\\ ==\\ 1\\\n\\#\\ fails\\ with\\ pytest\\-randomly,\\ passes\\ with\\ \\-p\\ no:randomly",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "pytest-randomly shuffles test order each run; order-dependent tests or shared state cause intermittent failures that were hidden by alphabetical ordering.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest-randomly 每次运行打乱测试顺序；顺序相关的测试或共享状态导致间歇性失败，这些失败在字母序下被隐藏。",
  "versions": [
    {
      "version": "3.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Hides order dependencies and lets bugs ship; the same issue will reappear under xdist or CI parallelism.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Masks the bug for that seed; other seeds still fail and the underlying leak remains.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Requires pytest-ordering and creates brittle coupling; doesn't fix leaked state.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "pytest -p randomly --randomly-seed=12345 tests/ -x\n# identify the leak, then fix with autouse reset fixture",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "@pytest.fixture(autouse=True)\ndef reset_globals():\n    myapp.state.clear()\n    yield\n    myapp.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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-12-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}