{
  "id": "python/pytest-xdist-order-dependent",
  "signature": "AssertionError: assert 0 == 1\n# passes with -p no:xdist, fails with -n auto",
  "signature_zh": "AssertionError: assert 0 == 1\n# 使用 -p no:xdist 通过，使用 -n auto 失败",
  "regex": "AssertionError:\\ assert\\ 0\\ ==\\ 1\\\n\\#\\ passes\\ with\\ \\-p\\ no:xdist,\\ fails\\ with\\ \\-n\\ auto",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Tests share global state (module-level dict, singleton, or DB row) that is mutated by one test and relied upon by another. pytest-xdist distributes tests across workers, breaking the implicit ordering.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试共享全局状态（模块级字典、单例或数据库行），一个测试修改后被另一个测试依赖。pytest-xdist 将测试分发到不同 worker，破坏了隐式顺序。",
  "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 underlying state leak and defeats the purpose of using xdist for speed.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Shuffling makes the flakiness worse and harder to reproduce, not better.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "@pytest.fixture(autouse=True)\ndef reset_state():\n    mypkg.cache.clear()\n    yield\n    mypkg.cache.clear()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "pytest -n auto --dist=loadscope",
      "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": "2024-06-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}