-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
106 lines (97 loc) · 4.27 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
import unittest
import HTMLTestReportCN
import time
import shutil
import sys
from util import *
import re
import os,sys
from client import *
data= os.system('python./LivenessHackDetect1.py')
os.system('python./LivenessSelfieVerification.py')
def get_value(dic, name):
source = dic.get(name)
if source is None or source == '':
return None
else:
variable_regexp = r"\$([\w_]+)"
result = re.findall(variable_regexp, source)
if len(result) > 0:
value = DATA.get(result[0])
if value:
source = source.replace('$'+result[0], value)
else:
return None
return source
if __name__ == '__main__':
suite = unittest.defaultTestLoader.discover(start_dir=base_dir + '/interface', pattern='VerifyIdNameBankcard_JDSK.py')
#suite = unittest.defaultTestLoader.discover(start_dir=base_dir + '/interface', pattern='DbInfo.py')
# suite = unittest.TestSuite()
# cases = util.read_runconfig(base_dir + '/config.xml', 'cases')c
now = time.strftime("%Y-%m-%d %H_%M_%S")
# for case in cases:
# p_name = case.split('-')[0]
# c_name = case.split('-')[1]
# # p = importlib.import_module(package='cases.' + p_name, name=p_name)
# FUNC_TEMPLATE1 = 'from interface.{package} import {classes}'
# FUNC_TEMPLATE2 = 'suite.addTest({case}("test_{method}"))'
# exec(FUNC_TEMPLATE1.format(package=p_name, classes=p_name))
# exec(FUNC_TEMPLATE2.format(case=p_name, method=c_name))
title = '%s.html' % now
fp = open(os.path.join(base_dir, 'report', title), 'wb')
HTMLTestReportCN.HTMLTestRunner(stream=fp, title='接口测试报告').run(suite)
fp.close()
# shutil.copyfile(sys.argv[0] + '\\..\\report\\' + title, sys.argv[0] + '\\..\\report\\report.html')
# excel加载用例模式下
# now = time.strftime("%Y-%m-%d %H_%M_%S")
# result_path = base_dir + '/result/' + now + '_result.csv'
# case_path = base_dir + '/excel_cases/%s.xlsx' % read_runconfig(base_dir+'/config.xml', 'excelcases')[0]
# cases = util.read_config_excel(case_path, '用例').get('用例')
# if cases:
# suite = unittest.TestSuite()
# for case in cases:
# id = get_value(case, '用例编号')
# des = get_value(case, '用例描述')
# url = get_value(case, '地址')
# method = get_value(case, '方法类型')
# type = get_value(case, '参数类型')
# headers = get_value(case, '请求头')
# files = get_value(case, '文件参数')
# data = get_value(case, '参数')
# checks = get_value(case, '检查点')
# if not headers:
# headers = {}
# if not files:
# files = {}
# if not data:
# data = {}
# if checks:
# checks = checks.split('&')
# FUNC_TEMPLATE = """class {classes}(unittest.TestCase):
# def test_{id}(self):
# '''{des}'''
# url = '{url}'
# method = Method.{method}
# type = Type.{type}
# headers = {headers}
# files = {files}
# data = {data}
# path = '{path}'
# client = Client(url=url, method=method, type=type)
# client.set_headers(headers)
# client.set_files(files)
# client.set_data(data)
# client.send()
# client.write_to_csv(path)\n"""
# func = FUNC_TEMPLATE.format(classes=id.upper(), id=id, des=des, url=url, method=method, type=type,
# headers=headers, files=files, data=data, path=result_path)
# for check in checks:
# func += ' client.%s\n' % check
# exec(func)
# ADD = 'suite.addTest({case}("test_{method}"))'
# exec(ADD.format(case=id.upper(), method=id))
# title = '%s.html' % now
# fp = open(os.path.join(base_dir, 'report', title), 'wb')
# HTMLTestReportCN.HTMLTestRunner(stream=fp, title='接口测试报告').run(suite)
# fp.close()
# shutil.copyfile(sys.argv[0] + '\\..\\report\\' + title, sys.argv[0] + '\\..\\report\\report.html')