# AttributeError: Mock object has no attribute 'fetch'
# with autospec=True
AttributeError: Mock object has no attribute 'fetch'

- **ID:** `python/unittest-mock-autospec-attribute`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

autospec=True builds a spec from the target object. If the target is a module or class where 'fetch' is defined dynamically (e.g., added in __init__ or via setattr), autospec cannot see it and the mock lacks the attribute.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Autospec the instance instead of the class:

instance = MyClient()
with patch.object(instance, 'fetch', autospec=True) as m:
    ...
   ```
2. **** (88% success)
   ```
   Use create_autospec on an instance with spec_set for stricter checks:

from unittest.mock import create_autospec
m = create_autospec(MyClient(), spec_set=True)
   ```

## Dead Ends

- **** — Loses signature validation and lets typos in call arguments pass silently. (70% fail)
- **** — Works but bypasses autospec and does not validate the signature of fetch. (60% fail)
