# AttributeError: <module 'app.services' from '/app/services.py'> does not have the attribute 'send_email'

- **ID:** `python/pytest-mock-patch-target`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

patch() targets a name that does not exist in the module at patch time, usually because the function is imported under a different name, lives in another module, or the import happens at call time.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   Patch where the name is looked up (the consumer module):

with patch('app.notifications.send_email') as m:
    notify_user()
    m.assert_called_once()
   ```
2. **** (88% success)
   ```
   Verify the actual attribute name:

python -c "import app.services; print([n for n in dir(app.services) if 'email' in n])"
   ```

## Dead Ends

- **** — create=True adds the attribute for the mock but does not change the code under test, so the real function is still called. (85% fail)
- **** — If the consumer did `from x import send_email`, patching x.send_email does not affect the local reference. (80% fail)
