# RuntimeError: Mock object has no attribute 'assert_called_once_with' after test body? No — actually: AttributeError: 'function' object has no attribute 'assert_called_once'

- **ID:** `python/pytest-mock-mocker-scope`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The mocker.patch target replaced the wrong object or the patch was applied after the code under test captured a reference, so the assertion runs against the real function, not a Mock.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (93% success)
   ```
   def test_send(mocker):
    m = mocker.patch('app.mailer.smtplib.SMTP')
    send_email('a@b.c')
    m.assert_called_once()
    m.return_value.sendmail.assert_called_once()
   ```
2. **** (85% success)
   ```
   def test_send(mocker):
    m = mocker.patch('app.mailer.smtplib.SMTP')
    from app.mailer import send_email  # import after patch
    send_email('a@b.c')
    m.assert_called_once()
   ```

## Dead Ends

- **** — The real function has no such method; you must assert on the returned mock object. (90% fail)
- **** — Patches a different attribute path, so the code under test still uses the real function. (80% fail)
