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

- **ID:** `python/unittest-mock-patch-target-not-found`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

unittest.mock.patch targets the name where it is looked up, not where it is defined. If services.py does `import requests` and calls `requests.get`, patch 'myapp.services.requests.get'. If it does `from requests import get`, patch 'myapp.services.get'.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Identify the binding style in the SUT and patch accordingly:
  # if SUT: import requests
  @patch('myapp.services.requests')
  def test_get(mock_req): ...
  # if SUT: from requests import get
  @patch('myapp.services.get')
  def test_get(mock_get): ...
   ```
2. **** (90% success)
   ```
   Use pytest-mock's mocker fixture which resolves the same lookup semantics:
  def test_get(mocker):
      mocker.patch('myapp.services.requests.get')
   ```

## Dead Ends

- **** — Patches the global requests module, not the reference the SUT uses; the real network call still fires. (75% fail)
- **** — Creates a separate binding; the SUT's binding remains untouched. (80% fail)
