# ImportError: attempted relative import with no known parent package

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

## Root Cause

pytest does not add the project root to sys.path by default when using certain configurations (e.g., no __init__.py in test directories or using rootdir incorrectly). Relative imports in test files then fail.

## Version Compatibility

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

## Workarounds

1. **** (93% success)
   ```
   # pytest.ini
[pytest]
pythonpath = .

# Or in pyproject.toml:
# [tool.pytest.ini_options]
# pythonpath = ["."]
   ```
2. **** (88% success)
   ```
   pip install -e .
# Then absolute imports work from anywhere
   ```

## Dead Ends

- **** — The current working directory may not be the project root when pytest is invoked from a different location. This is fragile and non-portable. (75% fail)
- **** — This may work locally but breaks when the package is installed or when tests are run from a different directory. It also violates package structure conventions. (65% fail)
