# fixture 'db_session' 未找到

- **ID:** `python/fixturenotfounderror-fixture-not-found`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Pytest 无法找到 fixture，因为它未定义、未导入或在测试函数中拼写错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## 解决方案

1. **Define fixture in conftest.py at the appropriate level** (95% 成功率)
   ```
   # conftest.py
@pytest.fixture
def db_session():
    return create_session()
   ```
2. **Use @pytest.fixture decorator in test file** (90% 成功率)
   ```
   @pytest.fixture
def db_session():
    return create_session()
   ```

## 无效尝试

- **Defining fixture in the same file but with wrong name** — Fixture name must match exactly; typos cause not found errors. (70% 失败率)
- **Using fixture from conftest without importing** — conftest fixtures are automatically available, but only if conftest is in the correct directory. (50% 失败率)
