从XML调用Python函数

时间:2015-10-07 16:35:34

标签: python xml

我有一个小型测试计划lib_procs.pymain_test.pytest_engine.py。现在main_test obj在test_engine.py中实例化。 obj用于调用main_test.py中的execute方法。在execute方法中调用procs.run_cmd(msg,cmd),它发送命令并返回消息。

lib_procs.py

def run_cmd(msg, cmd):
    #send hardware command and return something
    #it has other hardware specific method too

main_test.py

import lib_procs as procs
class main_test(object):
    def __init__(self, xmlpath, name)
     #initialize

    def execute(self):
       #Currently
       #parse xml
       msg = xml.msg
       cmd = xml.cmd
       output = procs.run_cmd(cmd, msg)
       #Do other things too

TestEngine.py

   if __name__ == "__main__::
       test_obj = main_test(xmlpath, test_name)
       test_obj.execute()

我想要做的是能够运行run_cmd但是通过XML文件。 XML文件应该包含要调用的函数的信息。这应该在main_test.py中提取。这样做的目的是使测试框架通用,可以通过更改XML中的信息由其他人使用。现在procs.run_cmd是特定于硬件的。有可能吗?

0 个答案:

没有答案