用catkin_make tes触发python rostest

2024-09-21 01:11:11 发布

您现在位置:Python中文网/ 问答频道 /正文

目标是:

我想通过调用包根目录中的catkin_make test在ros环境中通过rostest触发python单元测试。在

ros的版本是python2.7.3的hydro版本

工作原理:

official instructions中,我编写了一个测试,当使用命令rostest jenkins_test_repro testAll.test和相关的here调用它时,它工作得很好。在

在直接执行脚本时也能很好地工作。。。在

测试输出:

/home/USER/VirtEnvPython/bin/python /home/USER/sandbox/metric_tester/src/jenkins_test_repro/scripts/TestMetricStarter.py
[ROSUNIT] Outputting test results to /home/USER/.ros/test_results/jenkins_test_repro/rosunit-MetricStarter.xml
test_server_feedback ... ok
test_true ... ok
-------------------------------------------------------------
SUMMARY:
 * RESULT: SUCCESS
 * TESTS: 2
 * ERRORS: 0 []
 * FAILURES: 0 []

测试文件:

^{pr2}$

“启动”-文件:

<launch>
    <test test-name="MetricStarter" pkg="jenkins_test_repro" type="TestMetricStarter.py" />
</launch>

问题是:

为了通过catkin_make test调用测试,我需要在CMakeLists.txt文件. 我想出了三种方法来做到这一点,但对我来说,我还不清楚我真正需要做什么。对于所有的方式,我做了一个干净的构建(删除构建/开发和重新构建catkin工作区)

  1. 因为rostest的使用以及与工作命令行执行的类比

    add_rostest(test/testAll.test)
    

    但测试似乎没有执行:

    Running tests...
    Test project /home/USER/sandbox/metric_tester/build
        Start 1: _ctest_jenkins_test_repro_rostest_test_testAll.test
    1/1 Test #1: _ctest_jenkins_test_repro_rostest_test_testAll.test ...   Passed    1.64 sec
    
    100% tests passed, 0 tests failed out of 1
    
    Total Test time (real) =   1.65 sec
    catkin_make test  4.58s user 0.54s system 79% cpu 6.404 total
    

    我也试过了

    add_rostest(scripts/TestMetricStarter.py)
    

    导致以下错误

    Running tests...
    Test project /home/USER/sandbox/metric_tester/build
        Start 1: _ctest_jenkins_test_repro_rostest_scripts_TestMetricStarter.py
    1/1 Test #1: _ctest_jenkins_test_repro_rostest_scripts_TestMetricStarter.py ...***Failed    0.46 sec
    
    0% tests passed, 1 tests failed out of 1
    
    Total Test time (real) =   0.47 sec
    
    The following tests FAILED:
          1 - _ctest_jenkins_test_repro_rostest_scripts_TestMetricStarter.py (Failed)
    Errors while running CTest
    make: *** [test] Error 8
    Invoking "make" failed
    
  2. 刚试过,但这和罗斯特有关

    add_rostest_gtest(jenkins_test_repro test/testAll.test scripts/TestMetricStarter.py)
    

    但由于输出和请求的链接器语言,似乎是c/c++的东西

    CMake Error: CMake can not determine linker language for target:jenkins_test_repro
    CMake Error: Cannot determine link language for target "jenkins_test_repro".
    -- Generating done
    -- Build files have been written to: /home/USER/sandbox/metric_tester/build
    make: *** [cmake_check_build_system] Error 1
    
  3. official guide中是运行tests as part of ^{}的部分

    这会导致与第一种方式类似的行为

    catkin_add_nosetests(test/testAll.test)
    

    add_rostest(scripts/TestMetricStarter.py)相同

    catkin_add_nosetests(scripts/TestMetricStarter.py)
    

    add_rostest(test/testAll.test)

现在呢?在

所以仍然有一个问题,我必须如何在CMakeLists.txt文件... 对我来说,对于用python编写的单元测试,如何做到这一点还不清楚。对于c/cpp,有一些方法是可行的,但是对于python呢?在

由于构建场上的工具链,如果有一种方法可以用catkin_make test触发测试,那就更好了。此问题不要求其他绕过CMake的方法。在

如果需要更多信息,只需问:)。我希望有人能帮助或提示正确的解决办法。在

编辑:我在http://answers.ros.org上发布了同样的问题,因为我认为这仍然是一个非常具体的问题。如果有人有类似的问题,我会把它贴在这里。在


Tags: pytestaddhomemakescriptstestsjenkins
1条回答
网友
1楼 · 发布于 2024-09-21 01:11:11

如前所述,here解决方案起作用。目前还不清楚是什么真正改变了,因为add_rostest(test/testAll.test)在之前被测试过(第一种方法)。。。在

只是在CMakeLists.txt文件公司名称:

if (CATKIN_ENABLE_TESTING)
  add_rostest(test/testAll.test)
endif()

相关问题 更多 >

    热门问题