{
  "id": "python/unittest-testcase-order-error",
  "signature": "AssertionError: Test case order mismatch: expected test_second after test_first",
  "signature_zh": "断言错误：测试用例顺序不匹配：预期 test_second 在 test_first 之后",
  "regex": "AssertionError:\\ Test\\ case\\ order\\ mismatch:\\ expected\\ test_second\\ after\\ test_first",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Tests that rely on execution order (e.g., shared state) fail when unittest runs tests in alphabetical order by default.",
  "root_cause_type": "generic",
  "root_cause_zh": "依赖执行顺序的测试（例如共享状态）在 unittest 默认按字母顺序运行测试时失败。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "Renaming test methods to ensure alphabetical order",
      "why_fails": "This is fragile and may break if new tests are added with different names.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a global variable to track state across tests",
      "why_fails": "Shared state can lead to flaky tests and is against testing best practices.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use pytest with pytest-ordering plugin to specify test order explicitly.",
      "success_rate": 0.85,
      "how": "Install pytest-ordering and use @pytest.mark.run(order=1) decorators.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Refactor tests to be independent and not rely on order.",
      "success_rate": 0.9,
      "how": "Use setUp to initialize state for each test individually.",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}