# ImportError: attempted relative import with no known parent package

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

## Root Cause

A test file uses relative imports (e.g., from . import module) but is not part of a package, or is run as a script.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   From the project root, run: python -m pytest tests/
This ensures the current directory is in sys.path and relative imports work if tests are part of a package.
   ```
2. **** (95% success)
   ```
   pip install -e .
Then use absolute imports like 'from mypackage import module' in tests.
   ```

## Dead Ends

- **** — If the test is run as a top-level script, relative imports still fail because there is no parent package. (70% fail)
- **** — This may work but can break if the package structure changes or if the test is run from different directories. (60% fail)
