ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

rostest & Python - Multiple Test Fixtures In Single File

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

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 -0600

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 -0600 )edit

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

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 -0600 )edit

Your Answer

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

Add Answer

Question Tools



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

Seen: 1,315 times

Last updated: Feb 01 '17