ros2
test_error
ai_generated
true
colcon test:未找到包 'my_package' 的 pytest 框架
colcon test: Failed to find pytest framework for package 'my_package'
ID: ros2/colcon-test-no-pytest-framework
85%修复率
85%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ros2:humble | active | — | — | — |
| ros2:iron | active | — | — | — |
| colcon-core:0.14.0 | active | — | — | — |
| pytest:7.4.0 | active | — | — | — |
根因分析
colcon test 需要在 setup.cfg 或 package.xml 中配置测试框架(pytest 或 unittest);缺少或配置错误会导致测试发现失败。
English
colcon test requires a test framework (pytest or unittest) to be configured in setup.cfg or package.xml; missing or misconfigured entry causes test discovery failure.
官方文档
https://docs.ros.org/en/humble/Tutorials/Intermediate/Testing/Testing-Main.html解决方案
-
确保包根目录下的 setup.cfg 包含 [tool:pytest] 部分并列出测试路径。示例: [tool:pytest] testpaths = test 然后运行:colcon test --packages-select my_package
-
在 package.xml 中添加 pytest 的 test_depend 条目,并确保 test 目录中存在 conftest.py 或 __init__.py: <test_depend>python3-pytest</test_depend> 然后重新构建:colcon build --packages-select my_package && colcon test
无效尝试
常见但无效的做法:
-
Reinstalling pytest with pip without checking package configuration
70% 失败
pytest is already installed; the issue is in the package's test configuration, not the framework itself.
-
Adding a dummy test file without updating setup.cfg
85% 失败
colcon uses setup.cfg or package.xml to discover tests; a test file alone is insufficient.
-
Running pytest directly instead of colcon test
60% 失败
pytest may work locally but colcon test uses a different discovery mechanism; this doesn't fix the colcon integration.