# ERROR collecting tests/test_api.py
ImportError while importing test module 'tests/test_api.py'.
Hint: make sure your test modules/packages have valid Python names.
ModuleNotFoundError: No module named 'myapp'

- **ID:** `python/pytest-collection-error-importerror`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

pytest is invoked from a directory where the project root is not on sys.path, and the package is not installed in editable mode; pytest's rootdir-based sys.path insertion does not cover the source layout.

## Version Compatibility

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

## Workarounds

1. **** (97% success)
   ```
   pip install -e .
# or with pyproject:
pip install -e '.[dev]'
pytest
   ```
2. **** (94% success)
   ```
   # pyproject.toml
[tool.pytest.ini_options]
pythonpath = ["."]
testpaths = ["tests"]
   ```

## Dead Ends

- **** — Works locally but breaks in CI where cwd differs; also fails when tests are collected before the insert executes for other modules. (70% fail)
- **** — Does not persist across CI jobs or IDE runs; developers forget to export it and the error returns. (65% fail)
