# AssertionError: Expected 'send_email' to be called once. Called 0 times.

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

## Root Cause

A mock's assert_called_once() failed because the patched function was never invoked, usually due to patching the wrong module reference, an early return in the code under test, or the call happening in a different thread.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   Patch the name where it is used and assert against the same object:

with patch('app.orders.send_email') as m:
    place_order(order)
    m.assert_called_once_with('user@example.com')
   ```
2. **** (88% success)
   ```
   Debug by printing the mock's call list:

print(m.mock_calls)
print(m.call_args_list)
   ```

## Dead Ends

- **** — This only checks that it was called at least once, but the count is 0, so it still fails. (90% fail)
- **** — create=True creates a mock attribute but does not make the real code call it. (85% fail)
