-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun_this.py
37 lines (30 loc) · 1.21 KB
/
run_this.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding=utf-8
import unittest
import time
from excelddtdriver.common import HTMLTestRunner_api
import os
curpath = os.path.dirname(os.path.realpath(__file__))
report_path = os.path.join(curpath, "report")
if not os.path.exists(report_path): os.mkdir(report_path)
case_path = os.path.join(curpath, "case")
def add_case(casepath=case_path, rule="test*.py"):
'''加载所有的测试用例'''
# 定义discover方法的参数
discover = unittest.defaultTestLoader.discover(casepath,
pattern=rule,)
return discover
def run_case(all_case, reportpath=report_path):
'''执行所有的用例, 并把结果写入测试报告'''
htmlreport = reportpath+r"\result.html"
print("测试报告生成地址:%s"% htmlreport)
fp = open(htmlreport, "wb")
runner = HTMLTestRunner_api.HTMLTestRunner(stream=fp,
verbosity=2,
title="测试报告",
description="用例执行情况")
# 调用add_case函数返回值
runner.run(all_case)
fp.close()
if __name__ == "__main__":
cases = add_case()
run_case(cases)