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

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

## Root Cause

The test attempts to use mock assertion methods on a regular function instead of a Mock object. This happens when a function is patched incorrectly (e.g., using @patch without creating a Mock) or when the mock is not properly injected.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (98% success)
   ```
   from unittest.mock import patch

@patch('mymodule.my_function')
def test_my_function(mock_func):
    my_function()
    mock_func.assert_called_once()
   ```
2. **** (95% success)
   ```
   def test_my_function(mocker):
    mock_func = mocker.patch('mymodule.my_function')
    my_function()
    mock_func.assert_called_once()
   ```
3. **** (90% success)
   ```
   If you have a reference to a Mock, ensure you're calling the mock, not the original:

mock = Mock()
mymodule.my_function = mock
mymodule.my_function()
mock.assert_called_once()
   ```

## Dead Ends

- **** — Functions do not have mock assertion methods; this is a fundamental misunderstanding of the mock API. (98% fail)
- **** — Creating a Mock object does not replace the real function; the test still calls the original function. (90% fail)
- **** — mocker.patch requires a target string; omitting it raises a TypeError or patches the wrong object. (85% fail)
