# TypeError: object of type 'MagicMock' has no len()
During handling of the above exception, another exception occurred:
TypeError: unsupported operand type(s) for +: 'MagicMock' and 'MagicMock'

- **ID:** `python/pytest-mock-magic-method-not-mocked`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A regular mock.Mock was used where a MagicMock is required; only MagicMock supports magic methods like __len__, __add__, and __iter__.

## Version Compatibility

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

## Workarounds

1. **** (96% success)
   ```
   from unittest.mock import MagicMock, patch

with patch('myapp.container', new=MagicMock()) as m:
    m.__len__.return_value = 3
    assert len(container) == 3
   ```
2. **** (93% success)
   ```
   with patch('myapp.container', autospec=True) as m:
    m.__len__.return_value = 3
    assert len(container) == 3
   ```

## Dead Ends

- **** — Works for one magic method but breaks as soon as another (e.g., __iter__) is used; the mock is still not a full MagicMock. (80% fail)
- **** — configure_mock only sets named attributes; it does not add magic method support to a plain Mock. (90% fail)
