# PytestCollectionWarning: 无法收集测试类 'TestSession'，因为它有 __init__ 构造函数

- **ID:** `python/pytest-collection-warning-coroutine`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest 会收集任何以 Test* 命名的类，但拒绝有 __init__ 的类。名为 TestSession 的领域类（如 SQLAlchemy 模型）与 pytest 命名约定冲突。

## 版本兼容性

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

## 解决方案

1. **** (96% 成功率)
   ```
   Set __test__ = False on the class:

class TestSession(Base):
    __test__ = False
    __tablename__ = 'sessions'
   ```
2. **** (90% 成功率)
   ```
   Or rename the class to avoid the Test prefix (e.g., SessionRecord).
   ```

## 无效尝试

- **** — pytest checks the class attribute before instantiation; instance attributes are never seen. (85% 失败率)
- **** — The model is imported transitively by many tests; the warning persists. (80% 失败率)
