# AttributeError: Mock object has no attribute 'non_existent_method' when using autospec

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

## Root Cause

Using autospec=True in patch or create_autospec restricts the mock to only have attributes that exist on the original object, and accessing a non-existent attribute raises an AttributeError.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |

## Workarounds

1. **** (85% success)
   ```
   Ensure the attribute exists on the original object, or use autospec with a spec object that includes the attribute: create_autospec(MyClass, instance=True)
   ```
2. **** (75% success)
   ```
   Use spec_set instead of autospec to allow additional attributes while still checking existing ones.
   ```

## Dead Ends

- **** — Disabling autospec (autospec=False) may allow the test to pass but hides potential mismatches between the mock and the real API. (50% fail)
- **** — Adding the missing attribute to the original object may not be feasible if it's a third-party library. (40% fail)
