# ModuleNotFoundError: No module named 'myapp'

- **ID:** `python/pytest-import-mismatch-module-not-found`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

pytest is run from a directory where the project root is not on sys.path. This often happens when tests are in a subdirectory and the package is not installed, or when using src layout without proper configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Create conftest.py in the project root (even empty). pytest adds the rootdir to sys.path when it finds conftest.py.
   ```
2. **** (98% success)
   ```
   Run: pip install -e .
Ensure setup.py or pyproject.toml is present with proper package discovery.
   ```
3. **** (95% success)
   ```
   Run: python -m pytest tests/
This adds the current directory to sys.path.
   ```

## Dead Ends

- **** — The current working directory may not be the project root, and this is fragile. (70% fail)
- **** — This makes the parent directory not importable and often breaks relative imports. (80% fail)
