# 收集 tests/test_models.py 时出错
E   SyntaxError: 无效语法。也许你忘记了一个逗号？
  tests/test_models.py:42
    assert user.name == "alice" "bob"

- **ID:** `python/pytest-collection-failed-syntax`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试文件中的语法错误导致 pytest 无法导入，从而中止该文件的收集并显示收集错误而非测试失败。通常由隐式字符串拼接、缺少逗号或 Python 2 语法引起。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (98% 成功率)
   ```
   python -m py_compile tests/test_models.py
# or
python -c "import ast; ast.parse(open('tests/test_models.py').read())"
   ```
2. **** (95% 成功率)
   ```
   # Wrong
assert user.name == "alice" "bob"
# Right
assert user.name in {"alice", "bob"}
   ```

## 无效尝试

- **** — -x stops on first failure; the syntax error still aborts collection and no tests run. (85% 失败率)
- **** — Lets other files run, but the broken file still contributes zero tests, masking the real problem. (60% 失败率)
