common.py
4.11 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
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
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import operator
import configparser
import requests
import json
import re
from commons.Logging import Logger
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
log=Logger()
def get_global_config(file,section, key):
current_path=os.path.dirname(__file__)
src_path=os.path.dirname(current_path)
# global_setting_path=src_path+'/config/global_data.conf'
global_setting_path=src_path+'/config/'+file+".conf"
#验证文件是否存在
file_path = os.path.exists(global_setting_path)
if file_path:
#获取文件的数据
if isinstance(key,int):
log.error("key of section cannot be int Type :<%r> "%str(key))
raise Exception("key of section cannot be int Type :<%r> "%str(key))
else:
config = configparser.ConfigParser()
config.read(global_setting_path,encoding="utf-8")
return config.get(section, key)
else:
log.error("File Not Exist :<%r> "%str(global_setting_path))
raise Exception("File Not Exist :<%r> "%str(global_setting_path))
def get_api_config(api,section,key):
current_path=os.path.dirname(__file__)
src_path=os.path.dirname(current_path)
api_path=src_path+"/config/api/"
api_config_path=api_path+api+".conf"
#验证文件是否存在
file_path = os.path.exists(api_config_path)
if file_path:
#获取文件的数据
if isinstance(key,int):
log.error("key of section cannot be int Type :<%r> "%str(key))
raise Exception("key of section cannot be int Type :<%r> "%str(key))
else:
config = configparser.ConfigParser()
config.read(api_config_path,encoding="utf-8")
return config.get(section, key)
else:
log.error("File Not Exist :<%r> "%str(api_config_path))
raise Exception("File Not Exist :<%r> "%str(api_config_path))
def set_priority(priority_list):
#用户自定义优先级方法,设定有需要运行的用例优先级
global _global_priority
if priority_list:
_global_priority=priority_list
return _global_priority
else:
_global_priority=[1,2,3]
return _global_priority
def set_mark(case_mark):
#用户自定义优先级方法,设定有需要运行的用例优先级
global _global_mark
if case_mark:
_global_mark=case_mark
return _global_mark
else:
_global_mark=False
return _global_mark
def read_priority_list():
#需要重新设定一个方法来读取配置的全局优先级变量,且必须在全局变量初始化后使用,不然会报错
priority_list=[1,2,3]
try:
return _global_priority
except Exception as e:
return priority_list
def read_case_mark():
#需要重新设定一个方法来读取配置的全局优先级变量,且必须在全局变量初始化后使用,不然会报错
casemark=False
try:
return _global_mark
except Exception as e:
return casemark
def mark(tag=None,p=None):
#此处的try主要用于,当用户需要直接运行单个用例文件时,没提前_global_priority和_global_mark初始化
try:
#用户没有输入任何值
if _global_priority == [1,2,3] and _global_mark == False :
return True
#只指定用例标签
elif _global_priority == [1,2,3] and _global_mark != False:
if tag == _global_mark:
return True
else:
return False
#只指定用例优先级
elif _global_priority != [1,2,3] and _global_mark == False:
if p in _global_priority:
return True
else:
return False
#同时指定优先级和标签
elif _global_priority != [1,2,3] and _global_mark != False:
if p in _global_priority and tag == _global_mark:
return True
else:
return False
except Exception as e:
return True
# l=get_global_config("global_data", "email", "list")