-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_case.py
39 lines (39 loc) · 1.25 KB
/
run_case.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import unittest
import HTMLTestRunner
import time
import os
import shutil
casepath = ".//TestCase"
#casepath = '/Users/zhaozhiquan/automation/AndroidSdk/TestCase'
def Creatsuite():
#定义单元测试容器
testunit = unittest.TestSuite()
#定搜索用例文件的方法
discover = unittest.defaultTestLoader.discover(casepath, pattern='test0*', top_level_dir=None)
#将测试用例加入测试容器中
for testsuite in discover:
for casename in testsuite:
testunit.addTest(casename)
print testunit
return testunit
test_case = Creatsuite()
#获取系统当前日期
day = time.strftime('%Y-%m-%d')
#定义个报告存放路径,支持相对路径
aaa=os.path.exists('./result/'+day)
if aaa:
shutil.rmtree('./result/'+day)
os.mkdir('./result/'+day)
os.mkdir('./result/'+day+'/screencap')
filename = './result/'+day+'/result.html'
fp = file(filename, 'wb')
#定义测试报告
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'android联运sdk测试报告', description=u'用例执行情况:')
#运行测试用例
runner.run(test_case)
fp.close() #关闭报告文件