# AttributeError: 'NoneType' object has no attribute 'get'

- **ID:** `python/pytest-patch-stopall-early`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A test calls `patch.stopall()` in a `finally` block, which removes patches set up by `setUp` for subsequent tests in the same class. Later tests see the real (or None) object instead of the mock.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Use context managers or decorators so patches are scoped automatically:

@patch('mymod.dep')
def test_x(mock_dep):
    ...
   ```
2. **** (90% success)
   ```
   Use `addCleanup` to stop patches at the right time:

self.addCleanup(patcher.stop)
   ```

## Dead Ends

- **** — tearDown runs after each test, so the same problem persists across tests in the class. (80% fail)
- **** — Hard to detect failure reliably; patches still leak between tests. (70% fail)
