# 收集 tests/test_example.py 时出错
E   SyntaxError: invalid syntax

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

## 根因

测试文件或导入的模块中存在语法错误，导致 pytest 无法收集测试。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   python -m py_compile tests/test_example.py
Fix the reported syntax error, then rerun pytest.
   ```
2. **** (90% 成功率)
   ```
   flake8 tests/test_example.py
Address the reported issues.
   ```

## 无效尝试

- **** — pytest cannot collect tests from a file with syntax errors; the test will not run. (95% 失败率)
- **** — This hides the underlying syntax error and may cause other tests to fail if the module is imported elsewhere. (80% 失败率)
