forked from yanchunhuo/AutomationTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_api_test.py
More file actions
65 lines (59 loc) · 2.42 KB
/
Copy pathrun_api_test.py
File metadata and controls
65 lines (59 loc) · 2.42 KB
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
#-*- coding:utf8 -*-
# 作者 yanchunhuo
# 创建时间 2018/01/19 22:36
# github https://github.com/yanchunhuo
from common.pytest import deal_pytest_ini_file
from init.api.api_init import api_init
import argparse
import pytest
import sys
if __name__=='__main__':
parser=argparse.ArgumentParser()
parser.add_argument('-k','--keyword',help='只执行匹配关键字的用例,会匹配文件名、类名、方法名',type=str)
parser.add_argument('-d','--dir',help='指定要测试的目录',type=str)
parser.add_argument('-m','--markexpr',help='只运行符合给定的mark表达式的测试',type=str)
parser.add_argument('-s', '--capture', help='是否在标准输出流中输出日志,1:是、0:否,默认为0',type=str)
parser.add_argument('-r', '--reruns', help='失败重跑次数,默认为0',type=str)
parser.add_argument('-lf', '--lf', help='是否运行上一次失败的用例,1:是、0:否,默认为0',type=str)
parser.add_argument('-clr', '--clr', help='是否清空已有测试结果,1:是、0:否,默认为0', type=str)
args=parser.parse_args()
# 处理pytest文件
deal_pytest_ini_file()
# 初始化
print('开始初始化......')
api_init()
print('初始化完成......')
# 执行pytest前的参数准备
pytest_execute_params=['-c', 'config/pytest.ini', '-v', '--alluredir', 'output/api/']
# 判断目录参数
dir = 'cases/api/'
if args.dir:
dir=args.dir
# 判断关键字参数
if args.keyword:
pytest_execute_params.append('-k')
pytest_execute_params.append(args.keyword)
# 判断markexpr参数
if args.markexpr:
pytest_execute_params.append('-m')
pytest_execute_params.append(args.markexpr)
# 判断是否输出日志
if args.capture:
if int(args.capture):
pytest_execute_params.append('-s')
# 判断是否失败重跑
if args.reruns:
if int(args.reruns):
pytest_execute_params.append('--reruns')
pytest_execute_params.append(args.reruns)
# 判断是否只运行上一次失败的用例
if args.lf:
if int(args.lf):
pytest_execute_params.append('--lf')
# 判断是否清空已有测试结果
if args.clr:
if int(args.clr):
pytest_execute_params.append('--clean-alluredir')
pytest_execute_params.append(dir)
print('开始测试......')
exit_code=pytest.main(pytest_execute_params)