-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
60 lines (55 loc) · 2.46 KB
/
run.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 基础路径
import os
import platform
import sys
import time
import unittest
from BeautifulReport import BeautifulReport
from HTMLTestRunner import HTMLTestRunner
from HTMLTestRunner_Echarts import HTMLTestRunner_Echarts
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '')
print(base_path)
def run_test(argv):
print(argv)
case_dir = base_path + 'test_cases/'
discover = unittest.defaultTestLoader.discover(case_dir, pattern='test_*.py')
filename = base_path + 'report/report_test_gd.html'
fp = open(filename, 'wb')
title = '接口自动化测试报告'
# HTMLTestRunner
if argv[1] == '1':
runner = HTMLTestRunner(stream=fp,
title=title,
description='执行环境:系统:' + platform.platform() + ',Python版本:' + sys.version,
verbosity=2,
tester='yinqiang')
result = runner.run(discover)
# 饼状图报告
elif argv[1] == '2':
runner_echarts = HTMLTestRunner_Echarts(stream=fp,
title=title,
description='Interface AutoTest,执行环境:系统:' + platform.platform() +
',Python版本:' + sys.version,
verbosity=2)
result = runner_echarts.run(discover)
# BeautifulReport
elif argv[1] == '3':
result = BeautifulReport(discover)
result.report(filename=time.strftime("%Y-%m-%d %H:%M:%S") + '测试报告',
description='*****报告' + ' 执行环境:系统:' + platform.platform() + ',Python版本:' + sys.version,
report_dir=base_path + '/report')
else:
# 文本报告
file = base_path + 'report/report_test.txt'
f = open(file, 'w')
runner = unittest.TextTestRunner(stream=f)
result = runner.run(discover)
# print("all cases number: {}".format(result.testsRun))
# print("failed cases number: {}".format(result.failure_count))
# print("failed cases reason: {}".format(result.failures))
# print("error cases number: {}".format(result.error_count))
# print("error cases reason: {}".format(result.errors))
# print("success cases number: {}".format(result.success_count))
fp.close()
if __name__ == '__main__':
run_test(sys.argv)