# 收集 tests/test_models.py 时出错
  File "tests/test_models.py", 行 3
    def test_model(:
                  ^
SyntaxError: 无效语法

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

## 根因

测试模块（或它导入的模块）中的语法错误导致 pytest 无法收集它。该错误会中止整个文件的收集，因此该文件中的其他测试永远不会运行。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   python -m py_compile tests/test_models.py && pytest tests/test_models.py
   ```
2. **** (90% 成功率)
   ```
   ruff check tests/ && pytest
   ```

## 无效尝试

- **** — Lets other files run but the broken file still contributes zero tests, silently reducing coverage. (80% 失败率)
- **** — The tests in that file are permanently skipped; the syntax error is never fixed. (75% 失败率)
