# E   ImportError: cannot import name 'app' from 'myapp' (/path/to/myapp/__init__.py)

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

## Root Cause

pytest fails to collect tests because a test module imports a name that doesn't exist in the target module. This often occurs due to circular imports, missing __init__.py, or incorrect package structure.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   Check myapp/__init__.py and myapp/app.py:

# myapp/__init__.py
from .app import app

Ensure the app object is defined in myapp/app.py.
   ```
2. **** (90% success)
   ```
   Run: pip install -e .
Then in tests, use: from myapp import app
   ```
3. **** (85% success)
   ```
   In conftest.py:

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
   ```

## Dead Ends

- **** — This creates a dummy import that may hide the real issue and break other parts of the application. (90% fail)
- **** — This skips all tests, providing no validation and defeating the purpose of testing. (95% fail)
- **** — Relative imports only work within packages and may cause issues when running tests from different directories. (80% fail)
