{
  "id": "python/unittest-test-order-dependency",
  "signature": "AssertionError: test_b failed because test_a did not run first",
  "signature_zh": "断言错误：test_b 失败，因为 test_a 未先运行",
  "regex": "AssertionError:\\ test_b\\ failed\\ because\\ test_a\\ did\\ not\\ run\\ first",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "测试之间存在隐式依赖，但 unittest 默认按字母顺序运行，未按预期顺序执行。",
  "root_cause_type": "generic",
  "root_cause_zh": "测试之间存在隐式依赖，但 unittest 默认按字母顺序运行，未按预期顺序执行。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "依赖顺序脆弱，且重命名可能破坏其他引用。",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "全局状态在测试间泄漏，导致不可预测的结果。",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "在 setUpClass 中创建共享资源，每个测试独立使用，避免依赖。",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "安装 pytest-dependency 并标记 `@pytest.mark.dependency(depends=['test_a'])`。",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}