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

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

## Root Cause

A session-scoped fixture depends on a function-scoped fixture, which is not allowed because the function-scoped fixture is torn down after each test while the session fixture lives longer.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   @pytest.fixture(scope='session')
def db():
    conn = connect()
    yield conn
    conn.close()

@pytest.fixture(scope='session')
def seeded_db(db):
    seed(db)
    return db
   ```
2. **** (92% success)
   ```
   @pytest.fixture(scope='session')
def db():
    conn = connect()
    yield conn
    conn.close()

@pytest.fixture
def user(db):
    u = create_user(db)
    yield u
    db.delete(u)
   ```

## Dead Ends

- **** — Fixes the error but destroys the performance benefit; the expensive setup runs for every test. (30% fail)
- **** — Defaults to function scope, same performance regression, and may not match other fixtures that already use session. (50% fail)
