ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

rostest & Python - Multiple Test Fixtures In Single File

asked 2014-11-03 11:19:36 -0500

trianta2 gravatar image

With integration testing and rostest with Python, is it possible to define multiple test fixtures (classes inheriting from unittest.TestCase) and run them from a single file? Or do I need to create a new file for every test fixture I create?

I would like to have a single file which contains functional tests (tests which cover acceptable usage of code) and halt-catch-fire tests (tests which blatantly abuse code to evoke failure responses). Ideally the functional and HCF tests are classes which inherit from unittest.TestCase, and in turn these classes have multiple feature-specific tests.

However I am running into problems trying to run two integration tests from a single file. It's as if the first test's results are overwritten by the second test. Is this not the intended use of rostest? I.e. what I would like to do is have a file contain the following:

if __name__ == '__main__':
    import rostest
    rostest.rosrun('my_package', 'my_functional_test', FunctionalTestFixture, sys.argv) 
    rostest.rosrun('my_package', 'my_hcf_test', HcfTestFixture, sys.argv)

And my .test file contains:

<test test-name="my_node_test_suite" pkg="my_package" type="" />
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-11-03 12:53:12 -0500

ahendrix gravatar image

A reading of the rostest.rosrun source code reveals that it is in fact overwriting the results file with each function call:

rosunit.unitrun has a similar pattern and likely has the same flaw:

I think the best thing to do here is to split your tests into separate files. If this is a serious problem for you, you may want to consider filing a bug against rostest or submitting a patch which provides the behavior you need.

edit flag offensive delete link more


Thanks for your response. I'm basically trying to have a good tradeoff between # of files vs amount of use per file. I could split these tests into two files; one for functionality testing and one for HCF testing.

trianta2 gravatar image trianta2  ( 2014-11-03 13:10:00 -0500 )edit

answered 2017-02-01 08:12:52 -0500

otamachan gravatar image

It seems that this was solved in Kinetic. I can run multiple test fixtures in a single file with the following code.

if __name__ == '__main__':
    import rostest
    rostest.rosrun('my_package', 'my_test', __name__, sys.argv)
edit flag offensive delete link more


Thanks, it works in Kinetic.

longjie0723 gravatar image longjie0723  ( 2017-12-25 02:20:36 -0500 )edit

Question Tools



Asked: 2014-11-03 11:19:36 -0500

Seen: 1,435 times

Last updated: Feb 01 '17