# colcon test: 找不到测试依赖项：'python3-pytest'、'ros_testing'未安装

- **ID:** `ros2/colcon-test-failure-test-dependencies-not-installed`
- **领域:** ros2
- **类别:** test_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

colcon test需要安装package.xml中指定的测试依赖项（位于<test_depend>下）。缺少系统或ROS包会导致测试执行失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Humble | active | — | — |
| Iron | active | — | — |
| Rolling | active | — | — |

## 解决方案

1. ```
   Install test dependencies explicitly: rosdep install --from-paths src --ignore-src -r -y --rosdistro humble --include-test-dependencies. Then run colcon test again.
   ```
2. ```
   For missing system packages like python3-pytest, install manually: sudo apt-get install python3-pytest. For ROS packages like ros_testing: sudo apt-get install ros-humble-ros-testing.
   ```
3. ```
   If test dependencies are optional, temporarily remove them from package.xml and run colcon test with --packages-skip-build-failed to skip problematic packages.
   ```

## 无效尝试

- **** — The error will still occur for the selected package if dependencies are missing. The --packages-select flag doesn't bypass dependency resolution. (95% 失败率)
- **** — This command by default skips test dependencies unless --rosdistro and --include-test-dependencies are specified. (85% 失败率)
