{
  "id": "python/unittest-main-argv-error",
  "signature": "SystemExit: 2 when running unittest.main() with invalid arguments",
  "signature_zh": "SystemExit：使用无效参数运行 unittest.main() 时退出代码 2",
  "regex": "SystemExit:\\ 2\\ when\\ running\\ unittest\\.main\\(\\)\\ with\\ invalid\\ arguments",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "The command-line arguments passed to unittest.main() are invalid or unrecognized, causing the test runner to exit with an error.",
  "root_cause_type": "generic",
  "root_cause_zh": "传递给 unittest.main() 的命令行参数无效或无法识别，导致测试运行器以错误退出。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Passing sys.argv directly without validation",
      "why_fails": "If sys.argv contains invalid flags, the error persists.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using unittest.main(exit=False) to suppress exit",
      "why_fails": "This suppresses the exit but does not fix the argument error; tests may not run.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check the arguments passed to unittest.main() and correct them.",
      "success_rate": 0.9,
      "how": "unittest.main(argv=['first-arg-is-ignored', 'test_module'])",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use unittest.TestLoader and unittest.TextTestRunner to run tests programmatically instead.",
      "success_rate": 0.85,
      "how": "loader = unittest.TestLoader(); suite = loader.loadTestsFromModule(module); runner = unittest.TextTestRunner(); runner.run(suite)",
      "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-08-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}