python测试结果报告
我的问题是关于python单元测试报告的。 我使用的是xmlrunner包,它生成Jenkins使用的xunit输出。除此之外,我还想生成一个html输出,或者以一种很好的自定义格式打印输出。 注意:我已经知道HTMLTestRunner,但它并没有让我高兴。 有三个问题:python测试结果报告,python,unit-testing,reporting,Python,Unit Testing,Reporting,我的问题是关于python单元测试报告的。 我使用的是xmlrunner包,它生成Jenkins使用的xunit输出。除此之外,我还想生成一个html输出,或者以一种很好的自定义格式打印输出。 注意:我已经知道HTMLTestRunner,但它并没有让我高兴。 有三个问题: 我的测试不显示为套件组(报告不显示分组) 未显示测试细节(测试目的) 故障堆栈跟踪不应显示在为管理层制作的报告中 问题是如何迭代测试结果? 以下是我的测试运行程序代码: import unittest import os
- 我的测试不显示为套件组(报告不显示分组)
- 未显示测试细节(测试目的)
- 故障堆栈跟踪不应显示在为管理层制作的报告中
import unittest
import os, sys
import xmlrunner
def getSuites(root):
testSets = {"ts1":["tc1","tc2"], "ts2":["tc3","tc4"]}
suites = unittest.TestSuite()
for ts_name,ts in testSets.iteritems():
ts_dir = "%s/%s" % (root, ts_name)
sys.path.append(ts_dir)
print "ts_dir = %s" % ts_dir
for tc in ts:
module = __import__(tc,{},{},['1'])
suites.addTest(unittest.TestLoader().loadTestsFromModule(module))
return suites
if __name__ == "__main__":
root = os.path.dirname(os.path.abspath(__file__))
suites = getSuites(root)
results = xmlrunner.XMLTestRunner(output='test_reports').run(suites)
注:
抛出一个异常,指出_XMLTestResult不可iterable。
谢谢谢谢,这使我成为一个快乐的人。有这些文件吗?例如,x.output=0表示成功,1表示失败,3表示跳过,但2是什么?我阅读了源代码。()在这里,您可以找到“(成功、失败、错误、跳过)=范围(4)”。成功、失败、错误、跳过在中。
for r in results:
print r
for x in results.successes + results.failures + results.errors:
print x
#print x.get_description(), x.outcome