Pass parameters from launch file to python script in Unit Test(Rostest)

asked 2020-02-18 12:24:50 -0500

Buldoza gravatar image

updated 2020-02-18 12:43:41 -0500

I am working on implementing a rostest whereby i can pass parameters from a roslaunch file to my python script for testing. However my test is failing, and normally it should pass. I will paste my code here and also will be glad to get some feedback on why this is happening.

final goal will be to have one generic python template that many launch files can be used to do integration tes

my script reading parameters from the roslaunch file.

class itn_rtest_group1template(unittest.TestCase):
success = False
global topic1
global datatype1
global topic2
global datatype2
topic1=rospy.get_param("/topic1")
datatype1=rospy.get_param('/datatype1')
topic2=rospy.get_param("/topic2")
datatype2=rospy.get_param("/datatype2")

print(topic1,datatype1,topic2,datatype2)
#def __init__(self, *args, **kwargs):
    #rospy.loginfo("topic1: %s, datatype1: %s, topic2: %s, datatype2: %s", topic1,  datatype1, topic2, datatype2)
def callback(self,topic1,datatype1,topic2,datatype2):
    # This is the callback function for Group 1 testcase
    #self.rospy.loginfo('topic1 = %s', topic1)
    #self.rospy.loginfo('topic1 = %s', topic2)
    rospy.loginfo(rospy.get_caller_id() + "topic1: %s, datatype1: %s, topic2: %s, datatype2: %s",topic1,datatype1,topic2,datatype2)
    self.success = True
def test_WI_group1template(self):
    #This is the python Unit test generic template implementation
    rospy.init_node('WI_group1template', anonymous=True)  
    #rospy.loginfo("topic1: %s, datatype1: %s, topic2: %s, datatype2: %s", topic1,  datatype1, topic2,datatype2 )
    #print("start integration testing node")
    rospy.Subscriber("topic_name", String,self.callback,(topic1, datatype1))
    rospy.Subscriber("topic_name", String, self.callback,(topic2, datatype2))
    timeout_t = time.time() + 5.0
    while (not rospy.is_shutdown() and time.time() < timeout_t and(not self.success)):
        time.sleep(0.1)
    self.assert_(self.success)

if __name__ == '__main__': import rosunit try: rostest.rosrun(PKG, 'WI_group1template', itn_rtest_group1template) except rospy.ROSInterruptException: pass

<launch>
 <param name="topic1"  value="chatter"/>
 <param name="datatype1" value="String" />
 <param name="topic2" value="gemoto"/>
 <param name="datatype2" value="String"/>
 <node name="WI_group1template" pkg="itn_rtest" type="int_testtemplate_group1.py" output="screen" 
  clear_params="true"/>   
<test test-name="WI_XXXX" pkg="itn_rtest" type="int_testtemplate_group1.py" >    </test>  </launch>

ERROR log "False is not true File "/usr/lib/python2.7/unittest/case.py", line 329, in run testMethod() File "/home/user/integrationtest/src/itn_rtest/test/int_testtemplate_group1.py", line 65, in test_WI_group1template self.assert_(self.success) File "/usr/lib/python2.7/unittest/case.py", line 422, in assertTrue raise self.failureException(msg) ------------------------------------------------------------------"

edit retag flag offensive close merge delete