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

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

## Root Cause

A session-scoped fixture requested monkeypatch (which is function-scoped), violating pytest's scope ordering rules.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   @pytest.fixture(scope="session")
def config(): return {"url": "http://x"}

@pytest.fixture
def patched(config, monkeypatch):
    monkeypatch.setitem(config, "url", "http://test")
    return config
   ```
2. **** (90% success)
   ```
   @pytest.fixture(scope="session")
def patched():
    with pytest.MonkeyPatch.context() as mp:
        mp.setenv("X", "1")
        yield
   ```

## Dead Ends

- **** — May break expensive setup assumptions and hides the real scope design issue. (60% fail)
- **** — Does not change scope mismatch behavior. (90% fail)
- **** — Markers do not alter fixture scope rules. (85% fail)
