--- a/tools/rostest/src/rostest/rostestutil.py +++ b/tools/rostest/src/rostest/rostestutil.py @@ -43,6 +43,18 @@ import os import sys import logging +import unittest + +class LegacyTestCase(unittest.TestCase): + """Class for patching deprecated TestCase method aliases""" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + assert_ = unittest.TestCase.assertTrue + assertEquals = unittest.TestCase.assertEqual + failIf = unittest.TestCase.assertFalse + def printlog(msg, *args): if args: --- a/tools/rostest/src/rostest/__init__.py +++ b/tools/rostest/src/rostest/__init__.py @@ -44,6 +44,7 @@ import rosunit import rosgraph +import rostestutil try: from importlib import reload --- a/tools/rostest/nodes/hztest +++ b/tools/rostest/nodes/hztest @@ -56,7 +56,7 @@ from threading import Thread -class HzTest(unittest.TestCase): +class HzTest(rostest.rostestutil.LegacyTestCase): def __init__(self, *args): super(HzTest, self).__init__(*args) rospy.init_node(NAME) --- a/tools/rosnode/test/check_rosnode_command_online.py +++ b/tools/rosnode/test/check_rosnode_command_online.py @@ -50,7 +50,7 @@ time.sleep(0.1) os.kill(popen.pid, signal.SIGKILL) -class TestRosnodeOnline(unittest.TestCase): +class TestRosnodeOnline(rostest.rostestutil.LegacyTestCase): def setUp(self): self.vals = set() --- a/tools/rostest/test/test_clean_master.py +++ b/tools/rostest/test/test_clean_master.py @@ -37,8 +37,9 @@ import rospy import rosunit +import rostest -class CleanMasterTest(unittest.TestCase): +class CleanMasterTest(rostest.rostestutil.LegacyTestCase): def test_clean_master(self): self.failIf(rospy.has_param('dirty')) --- a/tools/rostest/test/test_distro_version.py +++ b/tools/rostest/test/test_distro_version.py @@ -39,7 +39,7 @@ import rostest import subprocess -class VersionTest(unittest.TestCase): +class VersionTest(rostest.rostestutil.LegacyTestCase): def test_distro_version(self): val = (subprocess.Popen(['rosversion', '-d'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] or b'').decode().strip() --- a/tools/rostest/nodes/paramtest +++ b/tools/rostest/nodes/paramtest @@ -53,7 +53,7 @@ CLASSNAME = 'paramtest' -class ParamTest(unittest.TestCase): +class ParamTest(rostest.rostestutil.LegacyTestCase): def __init__(self, *args): super(ParamTest, self).__init__(*args) rospy.init_node(CLASSNAME) --- a/tools/rostest/src/rostest/runner.py +++ b/tools/rostest/src/rostest/runner.py @@ -110,7 +110,7 @@ def fn(self): done = False while not done: - self.assert_(self.test_parent is not None, "ROSTestParent initialization failed") + self.assertTrue(self.test_parent is not None, "ROSTestParent initialization failed") test_name = test.test_name @@ -118,7 +118,7 @@ #launch the other nodes succeeded, failed = self.test_parent.launch() - self.assert_(not failed, "Test Fixture Nodes %s failed to launch"%failed) + self.assertTrue(not failed, "Test Fixture Nodes %s failed to launch"%failed) #setup the test # - we pass in the output test_file name so we can scrape it @@ -161,7 +161,7 @@ if not _textMode or timeout_failure: if not timeout_failure: - self.assert_(os.path.isfile(test_file), "test [%s] did not generate test results"%test_name) + self.assertTrue(os.path.isfile(test_file), "test [%s] did not generate test results"%test_name) printlog("test [%s] results are in [%s]", test_name, test_file) results = rosunit.junitxml.read(test_file, test_name) test_fail = results.num_errors or results.num_failures