# AttributeError: <class 'mypkg.Client'> has no attribute 'endpoint'

- **ID:** `python/pytest-monkeypatch-setattr-class`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

monkeypatch.setattr(Client, 'endpoint', ...) requires the attribute to already exist unless raising=False is passed; monkeypatch deliberately refuses to create new attributes.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   def test_client(monkeypatch):
    monkeypatch.setattr(Client, 'endpoint', 'http://test', raising=False)
   ```
2. **** (90% success)
   ```
   client = Client()
monkeypatch.setattr(client, 'endpoint', 'http://test')
   ```

## Dead Ends

- **** — Bypasses monkeypatch's automatic undo; the attribute leaks into subsequent tests. (75% fail)
- **** — The code under test instantiates the original Client, not the subclass, so the override has no effect. (80% fail)
