如何将python单元测试框架文件的输出写入.xml文件以在jenkins上可视化?
我有一个python文件testing.py,包含以下内容:如何将python单元测试框架文件的输出写入.xml文件以在jenkins上可视化?,python,xml,unit-testing,jenkins,Python,Xml,Unit Testing,Jenkins,我有一个python文件testing.py,包含以下内容: import subprocess import unittest DETACHED_PROCESS = 0x00000008 def open_exe(file,mode): if mode == 1: if type(file) is str: object = subprocess.Popen([file],creationflags=DETACHED_PROCESS,shell=
import subprocess
import unittest
DETACHED_PROCESS = 0x00000008
def open_exe(file,mode):
if mode == 1:
if type(file) is str:
object = subprocess.Popen([file],creationflags=DETACHED_PROCESS,shell=True)
if object.pid is None:
return 0
else:
print "Process id ", object.pid
return 1
if mode == 2:
if type(file) is str:
object = subprocess.Popen([file,"-configuration=" + "Other_base_0x1010.def"], creationflags=DETACHED_PROCESS,shell=True)
if object.pid is None:
return 0
else:
print "Process id ", object.pid
return 1
class testmyfunctions(unittest.TestCase):
def test_contains_simple_true(self):
self.assertEqual(open_exe("D:\\learning\\development\\MY_base.exe",1),1)
def test_first_process(self):
self.assertEqual(open_exe("D:\\learning\\Projects\\Other_base.exe", 2), 1)
if __name__ == '__main__':
unittest.main()
这个testing.py文件实际上打开了两个.exe,然后我制作了两个测试用例。我的问题是如何将testing.py的输出写入xml文件,以便在jenkins上可视化?有命令吗?至少建议我从哪里开始。您可以使用
nosetests
作为您的测试运行者。它与标准的unittest
tests兼容,并具有多种输出格式选项
见:
要创建JUnitXML,可以在命令行上指定--with xunit
。因此,要运行测试,只需执行以下操作:
$ nosetests --with-xunit
这将运行测试套件,并在当前工作目录中生成名为nosetests.xml的文件。首先,将xmlrunner安装到从属节点中。您可以参考以及如何在unittest中使用它 第二。回到jenkins,您需要通过两个步骤设置作业:
步骤1:“执行Shell”要执行unittest,请确保使用xmlrunner生成xml输出。
步骤2:“添加构建后操作”==>“发布JUnit测试报告”,然后将您的报告路径(在步骤1中生成)放在那里 祝你好运 尝试标记
--junit xml unit\u test\u results.xml
,并检查此项