# ScopeMismatch: 你尝试在 session 作用域的请求对象中访问 function 作用域的 fixture db

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

## 根因

session 作用域的 fixture 依赖了 function 作用域的 fixture，这是不允许的，因为 session fixture 的生命周期长于 function fixture。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Promote the dependency to a compatible scope:
@pytest.fixture(scope='session')
def db():
    ...
   ```
2. **** (88% 成功率)
   ```
   Or demote the dependent fixture to function scope:
@pytest.fixture(scope='function')
def client(db):
    ...
   ```

## 无效尝试

- **** — Defaults to function scope, which is the same problem. (60% 失败率)
- **** — Does not change scope compatibility. (70% 失败率)
