# ModuleNotFoundError: No module named 'my_package' during colcon test

- **ID:** `ros2/colcon-test-import-error-pkg-name`
- **Domain:** ros2
- **Category:** test_error
- **Error Code:** `COL-1002`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The Python package name in setup.py or setup.cfg does not match the actual directory name, or the package is not installed in the Python environment due to missing --symlink-install or build path issues.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ROS2 Foxy Fitzroy | active | — | — |
| ROS2 Galactic Geochelone | active | — | — |
| ROS2 Humble Hawksbill | active | — | — |

## Workarounds

1. **Ensure the Python package name in setup.py matches the directory name. For example, if your package directory is 'my_package', set `name='my_package'` in setup.py. Then rebuild with `colcon build --symlink-install` and run tests with `colcon test --packages-select my_package`.** (90% success)
   ```
   Ensure the Python package name in setup.py matches the directory name. For example, if your package directory is 'my_package', set `name='my_package'` in setup.py. Then rebuild with `colcon build --symlink-install` and run tests with `colcon test --packages-select my_package`.
   ```
2. **If using ament_python, verify that the `entry_points` in setup.py are correct and that the test directory has an `__init__.py` file. Run `colcon test --event-handlers console_direct+` to see the full error trace.** (85% success)
   ```
   If using ament_python, verify that the `entry_points` in setup.py are correct and that the test directory has an `__init__.py` file. Run `colcon test --event-handlers console_direct+` to see the full error trace.
   ```

## Dead Ends

- **** — Running pip install -e . in the package root may install it temporarily, but colcon will overwrite it on next build, and it doesn't fix the root cause. (50% fail)
- **** — Deleting the entire build directory and rebuilding is overkill; the issue is usually a configuration mismatch, not a corrupted build. (30% fail)
