# AttributeError: 'function' object has no attribute 'return_value'

- **ID:** `python/unittest-mock-return-value-attribute`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Trying to set return_value on a regular function instead of a Mock object, often because the patch decorator was not applied correctly or the target is not a mock.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Ensure the patch decorator is applied to the test function: @patch('module.function') def test(mock_func): mock_func.return_value = 42
   ```
2. **** (85% success)
   ```
   Use patch as a context manager: with patch('module.function') as mock_func: mock_func.return_value = 42
   ```

## Dead Ends

- **** — Wrapping the function in a Mock manually may work but bypasses the patch mechanism and can cause test isolation issues. (50% fail)
- **** — Using patch.object with a string instead of the actual object may still fail if the attribute does not exist. (60% fail)
