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

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

## Root Cause

A session-scoped fixture depends on a function-scoped fixture, which pytest forbids because the shorter-lived fixture cannot outlive its scope.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Align the dependent fixture's scope to session, or restructure so the session fixture does not depend on a function fixture:

@pytest.fixture(scope='session')
def engine():
    ...

@pytest.fixture
def db_session(engine):
    ...
   ```
2. **** (85% success)
   ```
   Use a factory fixture to create per-test objects from a session resource.
   ```

## Dead Ends

- **** — The error is about the fixture dependency graph, not the test; the mismatch persists. (85% fail)
- **** — Autouse does not change scope; the ScopeMismatch still occurs. (80% fail)
