ros2 test_error ai_generated true

colcon test: No test output files found in 'build/my_package/test_results'

ID: ros2/colcon-test-missing-test-output

Also available as: JSON · Markdown · 中文
85%Fix Rate
82%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
ROS2 Humble active
ROS2 Iron active
ROS2 Rolling active

Root Cause

The test runner (e.g., pytest, gtest) did not produce output files in the expected directory because tests failed to run, were skipped, or the CMake/ament test configuration did not set up output generation correctly.

generic

中文

测试运行器(如pytest、gtest)未在预期目录中生成输出文件,因为测试未能运行、被跳过,或CMake/ament测试配置未正确设置输出生成。

Official Documentation

https://docs.ros.org/en/humble/Tutorials/Intermediate/Testing/Testing.html

Workarounds

  1. 85% success Check if the test executable exists and can run: 'colcon test --packages-select my_package' and look for error messages in the console output. If tests are C++ gtest, ensure 'add_rostest' or 'ament_add_gtest' is used in CMakeLists.txt.
    Check if the test executable exists and can run: 'colcon test --packages-select my_package' and look for error messages in the console output. If tests are C++ gtest, ensure 'add_rostest' or 'ament_add_gtest' is used in CMakeLists.txt.
  2. 90% success Rebuild the package with '--cmake-args -DBUILD_TESTING=ON' and then run tests again. This ensures test targets are built.
    Rebuild the package with '--cmake-args -DBUILD_TESTING=ON' and then run tests again. This ensures test targets are built.
  3. 80% success For Python packages, ensure 'setup.py' or 'setup.cfg' has a 'test' section pointing to the correct test directory, and run 'colcon test' from the workspace root.
    For Python packages, ensure 'setup.py' or 'setup.cfg' has a 'test' section pointing to the correct test directory, and run 'colcon test' from the workspace root.

中文步骤

  1. 检查测试可执行文件是否存在并可运行:'colcon test --packages-select my_package',并在控制台输出中查找错误消息。如果是C++ gtest,确保在CMakeLists.txt中使用了'add_rostest'或'ament_add_gtest'。
  2. 使用'--cmake-args -DBUILD_TESTING=ON'重新构建包,然后重新运行测试。这确保测试目标被构建。
  3. 对于Python包,确保'setup.py'或'setup.cfg'中有指向正确测试目录的'test'部分,并从工作区根目录运行'colcon test'。

Dead Ends

Common approaches that don't work:

  1. Running 'colcon test' with '--event-handlers console_direct+' to see all output, but still no test results 80% fail

    This only increases verbosity; it does not fix the underlying issue of tests not producing output files.

  2. Manually creating the test_results directory to satisfy colcon 95% fail

    The directory must contain actual test output files; an empty directory does not resolve the error.