# Defining a dependency for (a Python) add_rostest call?

I have a unit test written in Python that depends on a package that generates messages. If I run catkin_make run_tests --only-pkg-with-deps my_package, the test fails because it can't find the message modules. (If I run catkin_make --only-pkg-with-deps my_package before running the tests, the tests pass because the messages are generated.)

Without a proper/obvious CMake target (because Python), what's the preferred way to force catkin/cmake to build the messages before running the tests? I don't want to have to build everything first, as I believe CMake targets should be self-sufficient.

My current approach, though hacky, is to make my rostest stanza look like this:

if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
find_package(my_msgs REQUIRED)

add_dependencies(_run_tests_my_package_rostest_test_my_test.test ${my_msgs_EXPORTED_TARGETS}) endif()  edit retag close merge delete ## Comments Maybe this issue will help? https://github.com/ros/ros_comm/issue... ( 2015-11-06 18:00:17 -0500 )edit ## 1 Answer Sort by » oldest newest most voted Looks like you can pass the message target dependencies to the add_rostest(...) call using the DEPENDENCIES target: http://docs.ros.org/api/catkin/html/h... So your code would look like: if(CATKIN_ENABLE_TESTING) find_package(rostest REQUIRED) find_package(my_msgs REQUIRED) add_rostest(tests/my_test.test DEPENDENCIES${my_msgs_EXPORTED_TARGETS})
endif()


I think that should work, but I haven't tried it myself.

more