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

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

## Root Cause

A session-scoped fixture depends on a function-scoped fixture (like tmp_path or monkeypatch), which pytest forbids because the narrower fixture cannot outlive the wider one.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   @pytest.fixture(scope='session')
def data_dir(tmp_path_factory):
    d = tmp_path_factory.mktemp('data')
    (d / 'file.txt').write_text('hi')
    return d
   ```
2. **** (85% success)
   ```
   @pytest.fixture(scope='session')
def cache():
    return {}

@pytest.fixture
def resource(cache, tmp_path):
    if 'r' not in cache:
        cache['r'] = build(tmp_path)
    yield cache['r']
   ```

## Dead Ends

- **** — Defeats the purpose of sharing expensive setup; tests slow down dramatically. (50% fail)
- **** — Raises the same ScopeMismatch at runtime; getfixturevalue does not change scopes. (85% fail)
