# AttributeError: Mock object has no attribute 'some_method'

- **ID:** `python/attributeerror-mock-object-has-no-attribute`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A mock object is created without specifying the attribute, and the code tries to access an undefined attribute.

## Version Compatibility

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

## Workarounds

1. **Configure mock with spec or autospec** (95% success)
   ```
   mock = Mock(spec=MyClass); mock.some_method.return_value = 42
   ```
2. **Set attribute directly on mock** (90% success)
   ```
   mock = Mock(); mock.some_method = MagicMock(return_value=42)
   ```

## Dead Ends

- **Adding attribute via mock.attach_mock** — attach_mock is for attaching additional mocks, not simple attributes. (60% fail)
- **Using mock.reset_mock()** — Reset clears call history but does not add missing attributes. (80% fail)
