Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

rostest can load tests from a dotted name#722

Closed
heuristicus wants to merge 1 commit intoros:indigo-develfrom
heuristicus:indigo-devel
Closed

rostest can load tests from a dotted name#722
heuristicus wants to merge 1 commit intoros:indigo-develfrom
heuristicus:indigo-devel

Conversation

@heuristicus
Copy link
Copy Markdown
Contributor

This is a simple solution to the issue, using unittest.TestLoader().loadTestsFromName. The dual-use (str or unittest.TestCase) of the test parameter could be changed to use a kwarg instead. That would necessitate test being an optional parameter which specifies the unittest.TestCase class, and some other parameter (test_from_name or something?) specifying a string from which tests should be loaded. That would probably require additional checks to ensure that at least one of the optional parameters existed.

You can check that the name-based loading works by changing line 56 in test_rosbag to

rostest.rosrun('test_rosbag', 'latched_pub', 'latched_pub.LatchedPub', sys.argv)

Here's a test you can run to check that suite loading works correctly. You can run it with rosrun test_rosbag tmp.py. Don't forget to chmod +x.

ros_comm/test/test_rosbag/test/tmp.py:

#!/usr/bin/env python

import unittest
import rostest
import rospy
import sys

class CaseA(unittest.TestCase):

    def runTest(self):
        self.assertTrue(True)

class CaseB(unittest.TestCase):

    def runTest(self):
        self.assertTrue(True)

class SuiteTest(unittest.TestSuite):

    def __init__(self):
        super(SuiteTest, self).__init__()
        self.addTest(CaseA())
        self.addTest(CaseB())

if __name__ == '__main__':
      rostest.rosrun('test_rosbag', 'temp_tests', 'tmp.SuiteTest', sys.argv)

Fixes #423.

@dirk-thomas
Copy link
Copy Markdown
Member

Can you please add a unit test for the new feature to this PR.

@heuristicus
Copy link
Copy Markdown
Contributor Author

I've added some tests, but couldn't really come up with a way of programmatically ensuring that the expected tests are actually loaded. I'm just assuming that loadTestsFromName will crash if you give it incorrect values for the dotted name. I'm not sure if there is a way to test expected failures, like giving a non-string, non-unittest.TestCase object to rosrun in the test parameter.

heuristicus added a commit to heuristicus/ros that referenced this pull request Dec 29, 2015
@heuristicus heuristicus force-pushed the indigo-devel branch 2 times, most recently from 5bb7578 to 6bdba57 Compare December 29, 2015 05:19
@stonier
Copy link
Copy Markdown
Contributor

stonier commented Jan 7, 2016

Had a chat about this - test should probably be testing the function itself (nosetest?) rather than running a rostest and crashing rostest itself.

@heuristicus
Copy link
Copy Markdown
Contributor Author

I've moved the tests to using the python unittest framework, and added some test cases for expected failures.

Also squashed to a single commit.

@heuristicus heuristicus force-pushed the indigo-devel branch 4 times, most recently from 61ed672 to 0b693b4 Compare January 8, 2016 01:24
@dirk-thomas
Copy link
Copy Markdown
Member

@ros-pull-request-builder test this please

@dirk-thomas
Copy link
Copy Markdown
Member

@ros-pull-request-builder retest this please

@dirk-thomas
Copy link
Copy Markdown
Member

Thank you for the improvement.

Jenkins is actually fine: http://build.ros.org/view/Jpr/job/Jpr__ros_comm__ubuntu_trusty_amd64/50/

I have cherry-picked the patch with the same modifications as ros/ros#104: 4c837a7

@dirk-thomas dirk-thomas closed this Mar 2, 2016
dirk-thomas added a commit that referenced this pull request Sep 19, 2016
@dirk-thomas
Copy link
Copy Markdown
Member

Several callers pass types instead of instances of unittest.TestCase. Therefore I had to relax the check: e341225

otamachan pushed a commit to otamachan/ros_comm that referenced this pull request Feb 1, 2017
dirk-thomas added a commit that referenced this pull request Mar 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants