import time,os
import sys
import unittest
from HTMLTestRunnerimport HTMLTestRunner
sys.path.append("./Interface")
#指定当前文件夹下的Interface目录
test_dir ="./interface"
#匹配开头为test的py文件
file =unittest.defaultTestLoader.discover(test_dir,pattern="*_test.py")
if __name__ =="__main__":
# 取当前时间
now = time.strftime("%Y-%m-%d %H-%M-%S",time.localtime(time.time()))
# 获取当前运行的.py文件所在的绝对路径
public_path = os.path.dirname(os.path.abspath(sys.argv[0]))
#保存的报告路径和名称
filename = public_path +"\\Report\\" + now +"report.html"
fp =open(filename,"wb")
runner = HTMLTestRunner(stream=fp,
title="接口自动化报告",
description="详细描述如下:"
)
#执行测试套件
runner.run(file)
fp.close()
网友评论