# ScopeMismatch: You tried to access the 'function' scoped fixture 'db' with a 'session' scoped request object

- **ID:** `python/pytest-fixture-scope-conflict`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

在pytest中，一个较高作用域的fixture（如session）尝试请求一个较低作用域的fixture（如function），导致pytest无法提供正确的实例，因为较低作用域的fixture会在测试结束后销毁。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.6 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   在fixture定义中修改scope参数，例如：@pytest.fixture(scope='session') def db(): ... 改为 @pytest.fixture(scope='function') def db(): ...
   ```
2. **** (70% success)
   ```
   def session_fixture(request):
    db = request.getfixturevalue('db')
    return db
   ```

## Dead Ends

- **** — 如果fixture本身需要每个测试独立状态，改为session会导致状态污染，且仍然无法解决根本的依赖关系错误。 (60% fail)
- **** — autouse只影响自动应用，不改变作用域依赖，错误依旧存在。 (90% fail)
