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

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

## Root Cause

A session/module-scoped fixture depends on a narrower-scoped fixture. pytest forbids a wider scope from consuming a narrower one because the narrower fixture would be torn down before the wider one.

## Version Compatibility

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

## Workarounds

1. **** (93% success)
   ```
   @pytest.fixture(scope='session')
def tmp_root(tmp_path_factory):
    return tmp_path_factory.mktemp('root')

@pytest.fixture(scope='session')
def settings(tmp_root):
    return load(tmp_root)
   ```
2. **** (90% success)
   ```
   @pytest.fixture(scope='session')
def db(tmp_path_factory):
    path = tmp_path_factory.mktemp('db')
    return init_db(path)
   ```

## Dead Ends

- **** — autouse doesn't change scope; the mismatch remains and pytest still raises ScopeMismatch. (80% fail)
- **** — The lambda still references the same fixture object; pytest resolves dependencies before invocation. (85% fail)
