# ModuleNotFoundError: No module named 'mock'

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

## Root Cause

Code imports the standalone backport `mock` package, but it is not installed (or the project targets Python 3 where unittest.mock should be used). The backport was only needed for Python 2 or very old Python 3.

## Version Compatibility

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

## Workarounds

1. **** (97% success)
   ```
   Replace the import with the stdlib module:

# from mock import patch  (remove)
from unittest.mock import patch, MagicMock

On Python 3.3+ this requires no installation.
   ```
2. **** (90% success)
   ```
   If legacy code must keep `import mock`, install the backport: `pip install mock` and add it to requirements-dev.txt.
   ```

## Dead Ends

- **** — The test then runs without any mocking, so the real network or DB is hit and tests fail or hang for a different reason. (85% fail)
- **** — Old mock versions are incompatible with modern patch targets and pytest, causing AttributeError or patching failures. (80% fail)
