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

转载于:https://www.cnblogs.com/x2x3/p/7525464.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值