Any way to use a TestSuite (instead a TestCase) with rostest?
UPDATE: See rosticket #423
I am using rostest under rosbuild to create unittests with Python.
I understand how to create unittests and rostests, for instance, to create a TestsCase and call it from rostest.rosrun:
import unittest
class MyFirstTestCase(unittest.TestCase):
def setUp(self):
# SetUp code
def tearDown(self):
# TearDown code
def test_something(self):
# some test code
def test_more_stuff(self):
# more test code
if __name__ == '__main__':
import rostest
rostest.rosrun('my_package', 'test_my_first_test_case', MyFirstTestCase)
However, I you want to create more TestCases it is good idea to add them to a TestSuite. For instance something like this:
import unittest
class MyFirstTestCase(unittest.TestCase):
# ...
class AnotherTestCase(unittest.TestCase):
def setUp(self):
# SetUp code
def tearDown(self):
# TearDown code
def test_another_thing(self):
# some test code
def test_yet_another_thing(self):
# more test code
if __name__ == '__main__':
def suite():
suite = unittest.TestSuite()
suite.addTest(MyFirstTestCase('test_something'))
suite.addTest(AnotherTestCase('test_another_thing'))
return suite
my_suite = suite()
import rostest
rostest.rosrun('my_package', 'test_my_first_test_suite', my_suite)
Note that the call to rostest.rosrun uses a unittest.TestSuite as argument rather than a unittest.TestCase.
But it seems that rostest.rosrun is not compatible with unittest.TestSuite, since after runing this code you would get a TypeError like the following:
rostest.rosrun('my_package','test_my_first_test_case', my_suite)
File "/opt/ros/groovy/lib/python2.7/dist-packages/rostest/__init__.py", line 136, in rosrun suite = unittest.TestLoader().loadTestsFromTestCase(test) File "/usr/lib/python2.7/unittest/loader.py", line 50, in loadTestsFromTestCase if issubclass(testCaseClass, suite.TestSuite): TypeError: issubclass() arg 1 must be a class
After reading the documentation and looking for some examples I did not found any way to call a TestSuite from rostest. Is it any way to properly create a TestSuite under rostest?
Some partial solution would be calling the different TestCases in different calls to rostest.rosrun like that:
rostest.rosrun('my_package', 'test_my_first_test_case', MyFirstTestCase)
rostest.rosrun('my_package', 'test_another_test_case', AnotherTestCase)
But, somehow, rostest only outputs the results for the second call to rostest.rosrun unless --text is passed (see this question). This is not desirable since --text is more verbose and increases testing time. Moreover, I believe using a TestSuite would be much more flexible than manully adding calls to rostest.rosrun.
EDIT: I edited the title to make the question clearer.