Ask Your Question

trigger python rostest with catkin_make test

asked 2014-10-21 06:46:57 -0600

Acuda gravatar image

the goal:

I want to trigger a python unit-test trough rostest in the ros-enviroment by calling catkin_make test in the package-root.

the version of ros is hydro with python 2.7.3

what works:

along the official instructions i wrote the test which works fine when calling it with the command rostest jenkins_test_repro testAll.test and the related "launch"-file as described here.

also working fine when direct executing the script...


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


#!/usr/bin/env python
PKG = 'jenkins_test_repro'
#import roslib; roslib.load_manifest(PKG)  # This line is not needed with Catkin.

import sys
import os
import rostest
import unittest
import requests

class TestMetricStarter(unittest.TestCase):

    def test_server_feedback(self):
        r = requests.get('http://SRV-ADR/MetricServer/default/index/MetricStarter' + os.getcwd())
        self.assertEqual(r.status_code, 200)

    def test_true(self):

if __name__ == '__main__':
    rostest.rosrun(PKG, 'MetricStarter', TestMetricStarter)


    <test test-name="MetricStarter" pkg="jenkins_test_repro" type="" />

the problem:

for invoking the test-stuff trough catkin_make test i need add the test in the CMakeLists.txt. i figured out 3 ways to do this and for me it's still unclear what i really need to do. for all ways i have done a clean build (removing build / devel and rebuilding catkin-workspace)

  1. because of the useage of rostest and the analogy to the working command-line-execution


    but the test seems not to be executed:

    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

    i also tried it with


    witch leads to following error

    Running tests...
    Test project /home/USER/sandbox/metric_tester/build
        Start 1:
    1/1 Test #1: ...***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 - (Failed)
    Errors while running CTest
    make: *** [test] Error 8
    Invoking "make" failed
  2. just tried while it had something to do with rostest,

    add_rostest_gtest(jenkins_test_repro test/testAll.test scripts/

    but seems to be c/c++ stuff due to the output and the requested linker language

    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. in the official guide is a section for running tests as part of make tests

    this leads into a similar behaviour as in the first way


    same as with add_rostest(scripts/ ...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-10-21 07:02:21 -0600

Acuda gravatar image

As described here the solution works. Still unclear is what had really had changed because add_rostest(test/testAll.test) was tested before (first approach)...

Just added following lines in the CMakeLists.txt:

edit flag offensive delete link more

answered 2018-06-26 13:22:58 -0600

130s gravatar image

the goal:

I want to trigger a python unit-test trough rostest in the ros-enviroment by calling catkin_make test in the package-root.

One obvious thing is there's not test option in catkin_make AFAIK; there's catkin_make run_test option.

I'm not super happy with how less currently some of the pages on you referred to are organized; they were originally written years ago and while there have been great additions, little effort might have been made to re-organize those wiki pages in order to improve readability (esp. for new users for ROS testing facility). There's a concise but much better documentation is available in Catkin's document (find "Configuring and running unit tests" section).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-10-21 06:29:33 -0600

Seen: 744 times

Last updated: Jun 26 '18