-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
112 lines (90 loc) · 2.92 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding: utf-8 -*-
# @Time : 2019-10-07 15:16
# @Author : ShaHeTop-Almighty-ares
# @Email : yang6333yyx@126.com
# @File : run.py
# @Software: PyCharm
import os
import sys
# 终端执行
path_1 = os.getcwd().split('AirCurrency')[0]
path_2 = 'AirCurrency/'
path = path_1 + path_2
sys.path.append(path)
print(path)
def ter_start():
# 终端命令穿参
ter_param = sys.argv[1:]
if len(ter_param) != 0:
print(ter_param)
p = ter_param[0]
print(p, type(p))
if p == 'all':
"执行所有用例"
print('all -> 执行所有用例')
file_prefix = 'test_*.py'
return file_prefix
if p == 'okex':
"""执行okex"""
print('okex case')
file_prefix = 'test_003_OrderAccuracy_001_OKEX.py'
return file_prefix
if p == 'bitfinex':
"""执行bitfinex"""
print('bitfinex case')
file_prefix = 'test_003_OrderAccuracy_002_BitFinex.py'
return file_prefix
if p == 'bitmex':
"""执行bitmex"""
print('bitmex case')
file_prefix = 'test_003_OrderAccuracy_003_BitMex.py'
return file_prefix
else:
print('参数错误...')
exit()
else:
print('else -> all test case')
# file_prefix = 'test_003_OrderAccuracy_001_OKEX.py'
# file_prefix = 'test_003_OrderAccuracy_002_BitFinex.py'
# file_prefix = 'test_003_OrderAccuracy_*.py'
# file_prefix = 'test_003_TestRunEnv.py'
file_prefix = 'test_003_*.py'
# return 'test_*.py'
return file_prefix
report_dir = './reports' # 报告路径
test_dir = './case/V2' # 测试路径
# file_prefix = '' # 文件前缀
file_prefix = ter_start()
import time
import unittest
from common.HTMLTestReportCN import HTMLTestRunner
from config.config import *
R = redis_obj(3)
if not R.get('RUN_ENV'):
R.set('RUN_ENV', 'dev')
print('报告路径:{}\n测试路径:{}\n文件前缀:{}\n'.format(report_dir, test_dir, file_prefix))
# 测试路径,匹配规则
discover = unittest.defaultTestLoader.discover(test_dir, pattern=file_prefix)
# 时间拼接报告名称
if R.get('RUN_ENV') == 'pro':
run_env = 'pro'
else:
run_env = 'dev'
now = time.strftime('%Y-%m-%d %H:%M:%S')
test_rp = '测试报告_{} {}_.html'.format(run_env, now)
report_name = report_dir + '/' + test_rp
# 打开-生成测试报告
with open(report_name, 'wb') as f:
print('f:', f)
runner = HTMLTestRunner(stream=f, title='自动化测试报告', description='回归测试')
runner.run(discover)
f.close()
if SEND_MAIL:
from common.PublicFunc import latest_report, send_mail
print('查找最新报告')
latest_report = latest_report(report_dir)
# print(latest_report)
print('发送报告到邮箱')
send_mail(latest_report)
if __name__ == '__main__':
pass