-
Notifications
You must be signed in to change notification settings - Fork 0
/
runAll.py
62 lines (55 loc) · 2.02 KB
/
runAll.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
import unittest
import HTMLTestRunnerNew
import os
import readConfig
# import logging
from common.log import Log as logging
on_off = 0
class AllTest():
def set_case_list(self):
fb = open(self.caseListFile)
for value in fb.readlines():
data = str(value)
if data != '' and not data.startswith("#"):
self.caseList.append(data.replace("\n", ""))
fb.close()
def set_case_suite(self):
self.set_case_list()
test_suite = unittest.TestSuite()
suite_model = []
for case in self.caseList:
case_file = os.path.join(readConfig.proDir, "testCase")
print(case_file)
case_name = case.split("/")[-1]
print(case_name + ".py")
discover = unittest.defaultTestLoader.discover(case_file, pattern=case_name + '.py', top_level_dir=None)
suite_model.append(discover)
if len(suite_model) > 0:
for suite in suite_model:
for test_name in suite:
test_suite.addTest(test_name)
else:
return None
return test_suite
def run(self):
try:
suit = self.set_case_suite()
if suit is not None:
logging.info("********TEST START********")
fp = open(resultPath, 'wb')
runner = HTMLTestRunnerNew.HTMLTestRunner(stream=fp, title='Test Report',
description='Test Description')
runner.run(suit)
else:
logging.info("Have no case to test.")
except Exception as ex:
logging.error(str(ex))
finally:
logging.info("*********TEST END*********")
# send test report by email
if int(on_off) == 0:
self.email.send_email()
elif int(on_off) == 1:
logging.info("Doesn't send report email to developer.")
else:
logging.info("Unknow state.")