-
Notifications
You must be signed in to change notification settings - Fork 40
/
start_test.py
executable file
·66 lines (54 loc) · 1.9 KB
/
start_test.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
import importlib # 动态导入模块
import os
import sys
import unittest
from datetime import datetime
from config import Config
from result.generator import generate
from result.suite import Suite
from result.text_test_result import result
from util.chrome import Browser
from util.utils import Utils
from util.web_tool import Tools
from util.xmind_reader import Xmind
sys.path.append(os.getcwd())
def create_suite():
get_xmind_case() # 生成Xmind
suite = Suite()
all_case = Tools.get_all_case()
case_info = {}
for k, v in all_case.items():
cls_name = importlib.import_module("{}.{}.{}".format(Config.suite_name, v, k))
case, case_name = Tools.get_case_cls(cls_name, v, dir(cls_name))
case_info.update({case_name: v}) # 对应用例和套件
case_list = Tools.get_case_name(case)
for c in case_list:
suite.addTest(case(c))
Config.case_info = case_info
return suite
def get_xmind_case():
for root, dirs, files in os.walk(Config.xmind):
for file in files:
if file.endswith("xmind_data"):
xd = Xmind(file)
data = xd.parse()
xd.parse_to_case(data)
def write_report(html):
file = "report{}.html".format(datetime.strftime(datetime.now(), "%Y-%m-%d %H-%M-%S"))
Utils.make_dir(Config.report_path)
filename = os.path.join(Config.report_path, file)
with open(filename, "w", encoding="utf-8") as f:
f.write(html)
with open(os.path.join(Config.report_path, "report.html"), "w", encoding="utf-8") as file:
file.write(html)
def run():
Browser.set_browser()
start = datetime.now()
suite = create_suite()
Config.CASE_NUM = len(getattr(suite, "_tests"))
runner = unittest.TextTestRunner(resultclass=result)
rt = runner.run(suite)
html, info, rv = generate(rt, start)
write_report(html)
if __name__ == "__main__":
run()