catkin: catkin_make run_tests - can't import Python code
Not sure if this is my fault or a bug. I prepared a test repository with minimal example: https://github.com/ZdenekM/rostest-test-repo. The thing is that there are two packages - one with a custom message and the other with rostest where I would like to use the message. When I run test like this rostest test_package test.test it succeeds - but it fails when I run catkin_make run_tests (see whole output below - it seems that messages are generated) with ImportError: No module named my_msgs.msg. What might be wrong?
Scanning dependencies of target tests
Scanning dependencies of target clean_test_results_test_package
Scanning dependencies of target _my_msgs_generate_messages_check_deps_MyMessage
[ 0%] Built target tests
Removing test result files from '/home/zdenal/test_workspace/build/test_results/test_package'
[ 0%] Built target clean_test_results_test_package
[ 0%] Built target _my_msgs_generate_messages_check_deps_MyMessage
Scanning dependencies of target my_msgs_generate_messages_cpp
Scanning dependencies of target my_msgs_generate_messages_py
Scanning dependencies of target my_msgs_generate_messages_lisp
[ 25%] [ 50%] [ 75%] Generating C++ code from my_msgs/MyMessage.msg
Generating Lisp code from my_msgs/MyMessage.msg
Generating Python from MSG my_msgs/MyMessage
[ 75%] Built target my_msgs_generate_messages_lisp
[100%] Generating Python msg __init__.py for my_msgs
[100%] Built target my_msgs_generate_messages_py
[100%] Built target my_msgs_generate_messages_cpp
Scanning dependencies of target _run_tests_test_package_rostest_test_test.test
-- run_tests.py: execute commands
/opt/ros/indigo/share/rostest/cmake/../../../bin/rostest --pkgdir=/home/zdenal/test_workspace/src/rostest-test-repo/test_package --package=test_package --results-filename test_test.xml --results-base-dir /home/zdenal/test_workspace/build/test_results /home/zdenal/test_workspace/src/rostest-test-repo/test_package/test/test.test
... logging to /home/zdenal/.ros/log/rostest-ZMThinkpad-30945.log
[ROSUNIT] Outputting test results to /home/zdenal/test_workspace/build/test_results/test_package/rostest-test_test.xml
Traceback (most recent call last):
File "/home/zdenal/test_workspace/src/rostest-test-repo/test_package/test/test.py", line 8, in <module>
from my_msgs.msg import MyMessage
ImportError: No module named my_msgs.msg
testtest_package_test ... FAILURE!
FAILURE: test [test_package_test] did not generate test results
File "/usr/lib/python2.7/unittest/case.py", line 331, in run
testMethod()
File "/opt/ros/indigo/lib/python2.7/dist-packages/rostest/runner.py", line 164, in fn
self.assert_(os.path.isfile(test_file), "test [%s] did not generate test results"%test_name)
File "/usr/lib/python2.7/unittest/case.py", line 424, in assertTrue
raise self.failureException(msg)
--------------------------------------------------------------------------------
[ROSTEST]-----------------------------------------------------------------------
[testtest_package_test][failed]
SUMMARY
* RESULT: FAIL
* TESTS: 0
* ERRORS: 0
* FAILURES: 1
ERROR: The following tests failed to run:
* testtest_package_test
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 31 (13 by maintainers)
Oh I was hit by this problem as well, and just wanted to confirm what ZdenekM experienced: the first solution did not work, the second did. A work-around yes, but a really annoying one.
Thank you for your detailed answer. The first approach does not work for me but the second does - great! Maybe, it would be nice to document this somewhere.
Please see #986 for a proposed patch which avoid the need for the mentioned workarounds.
Sure, using @ZdenekM’s repo https://github.com/ZdenekM/rostest-test-repo, here are my steps to reproduce the failure:
Open a new shell without any ROS scripts sourced or environment variables set and run the following commands (or paste to a script and run it all at once)
Expected Result: The test.py script errors with
ImportError: No module named my_msgs.msgAnd to reproduce the success, do the following after the above:
PYTHONPATH=line inbuild/catkin_generated/setup_cached.shcatkin_make run_testsExpected result: Test passes without errors.