{
  "id": "python/pytest-collection-error-syntax",
  "signature": "ERROR collecting tests/test_math.py\n  File \"tests/test_math.py\", line 7\n    assert add(1, 2) == 3\n                       ^\nSyntaxError: invalid syntax",
  "signature_zh": "收集 tests/test_math.py 时出错\n  File \"tests/test_math.py\", 第 7 行\n    assert add(1, 2) == 3\n                       ^\nSyntaxError: 无效语法",
  "regex": "ERROR\\ collecting\\ tests/test_math\\.py\\\n\\ \\ File\\ \"tests/test_math\\.py\",\\ line\\ 7\\\n\\ \\ \\ \\ assert\\ add\\(1,\\ 2\\)\\ ==\\ 3\\\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\^\\\nSyntaxError:\\ invalid\\ syntax",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A syntax error in the test file prevents pytest from importing it during collection, so the entire module is reported as an error rather than running any tests.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试文件中的语法错误阻止 pytest 在收集期间导入该文件，因此整个模块被报告为错误，而不是运行任何测试。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Skips the broken module but hides the syntax error and leaves the test suite silently incomplete.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "SyntaxError is raised at parse time, before any import statement executes, so the try/except never runs.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "python -m py_compile tests/test_math.py",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "# .pre-commit-config.yaml\nrepos:\n  - repo: https://github.com/pre-commit/pre-commit-hooks\n    rev: v4.6.0\n    hooks:\n      - id: check-ast",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}