# AttributeError: module 'unittest' has no attribute 'mock'

- **ID:** `python/unittest-module-has-no-attribute-mock`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

unittest.mock is a submodule that must be imported explicitly; `import unittest` alone does not expose `unittest.mock`, and in some environments a local file named unittest.py shadows the stdlib.

## Version Compatibility

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

## Workarounds

1. **** (98% success)
   ```
   from unittest import mock
# or
from unittest.mock import patch, MagicMock

with patch('module.func') as m:
    m.return_value = 42
   ```
2. **** (90% success)
   ```
   python -c "import unittest; print(unittest.__file__)"
# If it prints a path inside your project, rename that file (e.g. unittest_local.py).
   ```

## Dead Ends

- **** — If a local unittest.py shadows the stdlib, this imports the local file and still lacks .mock. (50% fail)
- **** — Star import does not import submodules and is discouraged; mock is still not bound. (80% fail)
