python HTML报告

http://www.cnblogs.com/puresoul/p/7490737.html


# coding:utf-8
import time
import unittest
import HTMLTestRunner #将这个包提前放到python的sipackage下
def all_case():

case_dir = "C:\\Users\\Administrator\\Desktop\\python3\\test_blog\\test_case\\twodir\\threedir" #待执行用例的目录
testcase = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(case_dir,
pattern="test*.py", #脚本名字开头
top_level_dir=None) #默认
# discover方法筛选出来的用例,循环添加到测试套件中
for test_suite in discover:
#添加用例到testcase
for test_case in test_suite:
testcase.addTests(test_case)
print(testcase)
return testcase

if __name__ == "__main__":
# 返回实例
now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) #时间
runner = unittest.TextTestRunner()
report_path = "C:\\Users\\Administrator\\Desktop\\ftp\\" +now+"result.html" #报告文件的位置
fp = open(report_path, "wb") #打开文件
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
title=u'这是我的自动化测试报告',
description=u'用例执行情况:')
runner.run(all_case()) #Run the given test case or test suite
fp.close() #Close the file
posted @ 2017-09-15 11:24  binghex  阅读(499)  评论(0编辑  收藏  举报