-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathrun.py
51 lines (43 loc) · 1.26 KB
/
run.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import sys
import time
import unittest
import sys
sys.path.append('../')
from report.HTMLTestRunner3 import HTMLTestRunner
def create_suite():
TestSuite = unittest.TestSuite() # 测试集
test_dir = './test/testcase'
# print(test_dir)
discover = unittest.defaultTestLoader.discover(
start_dir=test_dir,
pattern='test_login.py',
top_level_dir=None
)
for test_case in discover:
TestSuite.addTests(test_case)
# print(test_case)
return TestSuite
def report():
if len(sys.argv) > 1:
report_name = os.path.dirname(os.getcwd()) + '\\report\\' + sys.argv[1] + '_result.html'
print(report_name)
else:
now = time.strftime("%Y-%m-%d_%H_%M_%S_")
# 需要查看每段时间的测试报告,可以这样写:
# report_name = os.getcwd() + '\\report\\'+now+'result.html'
report_name = './report/result.html'
print(report_name)
return report_name
if __name__ == '__main__':
TestSuite = create_suite()
fp = open(report(), 'wb')
Runner = HTMLTestRunner(
stream=fp,
title='测试报告',
description='测试用例执行情况'
)
Runner.run(TestSuite)
fp.close()