common.py
4.36 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
124
125
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import configparser
import unittest
from discover import DiscoveringTestLoader
from commons.Logging import Logger
log=Logger()
def get_global_config(file,section, key):
"object file is *src/config/global_data.conf"
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):
"object file is *src/config/api/*.conf"
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 get_market_config(api,section,key):
"object file is *src/config/marketConfig/*.conf"
current_path=os.path.dirname(__file__)
src_path=os.path.dirname(current_path)
api_path=src_path+"/config/marketConfig/"
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 run_one(name):
test_suite = unittest.TestSuite()
#创建测试套
test_suite.addTest(name)
#显示运行用例
print("运行用例为{}".format(test_suite))
runner = unittest.TextTestRunner()
runner.run(test_suite)
def run_list(name):
test_suite = unittest.TestSuite()
test_suite.addTests(name)
#显示运行用例
print("运行用例为{}".format(test_suite))
# with open(file="E:\\PycharmWorkspace\\jmsf-re-local\\report\\test.log", mode="a", encoding="utf-8") as file:
# runner = unittest.TextTestRunner(stream=file,verbosity=2)
# runner.run(test_suite)
runner = unittest.TextTestRunner()
runner.run(test_suite)
def run_class(name):
test_cases = unittest.TestLoader().loadTestsFromTestCase(name)
#显示运行用例
print("运行用例为{}".format(test_cases))
runner = unittest.TextTestRunner()
runner.run(test_cases)
def run_Module(name):
test_cases = unittest.TestLoader().loadTestsFromModule(name)
#显示运行用例
print("运行用例为{}".format(test_cases))
runner = unittest.TextTestRunner()
runner.run(test_cases)
def run_Name(name):
test_cases = unittest.TestLoader().loadTestsFromName(name)
#显示运行用例
print("运行用例为{}".format(test_cases))
runner = unittest.TextTestRunner()
runner.run(test_cases)
def mylog(func):
def RebackTest(self):
print(func.__name__)
print(dir(func))
# print(self)
return func(self)
return RebackTest