# AttributeError: Mock object has no attribute 'send'

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

## Root Cause

A bare `Mock()` returns child mocks for any attribute access, but `MagicMock`/`Mock` with `spec=` restricts attributes. If a test uses `spec=` and the code calls a method not in the spec, this error appears.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Add the missing method to the spec's source class, or use `spec=` on the real class:

from unittest.mock import MagicMock
from mylib import Client
m = MagicMock(spec=Client)
# ensure Client actually defines .send()
   ```
2. **** (90% success)
   ```
   Use `autospec=True` in patch so the mock mirrors the real signature:

@patch('mymod.Client', autospec=True)
def test_client(MockClient):
    ...
   ```

## Dead Ends

- **** — Disables safety checks; typos in method calls are no longer caught and tests may pass silently. (60% fail)
- **** — With `spec_set=True` you cannot add new attributes; with plain `spec` this works but defeats the purpose. (50% fail)
