Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 在单元测试(Rostest)中将参数从启动文件传递到python脚本_Python 2.7_Unit Testing_Integration Testing_Ros - Fatal编程技术网

Python 2.7 在单元测试(Rostest)中将参数从启动文件传递到python脚本

Python 2.7 在单元测试(Rostest)中将参数从启动文件传递到python脚本,python-2.7,unit-testing,integration-testing,ros,Python 2.7,Unit Testing,Integration Testing,Ros,我正在致力于实现一个Python单元测试(rostest),通过它我可以将参数从roslaunch文件传递到我的Python通用脚本进行测试。然而,我的测试失败了,通常应该通过。我将把我的代码粘贴到这里,并且很高兴得到一些关于为什么会发生这种情况的反馈 最终目标是拥有一个通用python模板,许多启动文件可以使用该模板进行集成测试 我的脚本正在从roslaunch文件读取参数: class itn_rtest_group1template(unittest.TestCase): success

我正在致力于实现一个Python单元测试(rostest),通过它我可以将参数从roslaunch文件传递到我的Python通用脚本进行测试。然而,我的测试失败了,通常应该通过。我将把我的代码粘贴到这里,并且很高兴得到一些关于为什么会发生这种情况的反馈

最终目标是拥有一个通用python模板,许多启动文件可以使用该模板进行集成测试

我的脚本正在从roslaunch文件读取参数:

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)

if __name__ == '__main__':
    import rosunit  
    rostest.rosrun(PKG, 'WI_group1template', itn_rtest_group1template) 
class-itn\u rtest\u-group1模板(unittest.TestCase):
成功=错误
全球主题1
全局数据类型1
全球专题2
全局数据类型2
topic1=rospy.get_参数(“/topic1”)
datatype1=rospy.get_参数('/datatype1')
topic2=rospy.get_参数(“/topic2”)
datatype2=rospy.get_参数(“/datatype2”)
打印(主题1、数据类型1、主题2、数据类型2)
#定义初始化(self,*args,**kwargs):
#rospy.loginfo(“主题1:%s,数据类型1:%s,主题2:%s,数据类型2:%s”,主题1,数据类型1,主题2,数据类型2)
def回调(自我、主题1、数据类型1、主题2、数据类型2):
#这是组1测试用例的回调函数
#self.rospy.loginfo('topic1=%s',topic1)
#self.rospy.loginfo('topic1=%s',topic2)
rospy.loginfo(rospy.get_caller_id()+“主题1:%s,数据类型1:%s,主题2:%s,数据类型2:%s”,主题1,数据类型1,主题2,数据类型2)
自我成功=真实
def测试WI组1模板(自身):
#这是python单元测试通用模板实现
rospy.init_节点('WI_group1template',anonymous=True)
#rospy.loginfo(“主题1:%s,数据类型1:%s,主题2:%s,数据类型2:%s”,主题1,数据类型1,主题2,数据类型2)
#打印(“启动集成测试节点”)
Subscriber(“topic_name”,字符串,self.callback,(topic1,datatype1))
Subscriber(“topic_name”,字符串,self.callback,(topic2,datatype2))
超时时间=time.time()+5.0
而(不是rospy.is\u shutdown()和time.time()
启动文件如下所示

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

我的目标是拥有一个python脚本,在这个脚本中,我可以通过创建不同的roslaunch文件来测试软件中的不同通信,并通过python模板将读取和使用的roslaunch文件传递参数

当我运行我的roslaunch文件时,我得到了这个错误日志,如果我能得到一些关于这个的帮助,我会很高兴的


错误日志“False is not true File”/usr/lib/python2.7/unittest/case.py”,第329行,运行testMethod()文件/home/user/integrationtest/src/itn_rtest/test/int_testtemplate_group1.py,第65行,在test_WI_group1模板self.assert(self.success)文件/usr/lib/python2.7/unittest/case.py中“,第422行,在assertTrue raise self.failureException(msg)---------------------------------------------------------------------------”

决定将测试分离到不同的文件中,原因是多次运行测试不同的功能位超过参数服务器的值