#coding=utf-8
import sys
#reload(sys)
#sys.setdefaultencoding('utf8')
import unittest
from BeautifulReport import BeautifulReport
import os
from tomorrow import threads
#一个报告,模块分开
# 获取路径
import time
curpath = os.path.dirname(os.path.realpath(__file__))
casepath = os.path.join(curpath, "test")
if not os.path.exists(casepath):
print("测试用例需放到‘test’文件目录下")
os.mkdir(casepath)
reportpath = os.path.join(curpath, "report")
if not os.path.exists(reportpath): os.mkdir(reportpath)
def add_case(case_path=casepath, rule="*sta.py"):
'''加载所有的测试用例'''
discover = unittest.defaultTestLoader.discover(case_path,
pattern=rule,
top_level_dir=None)
return discover
@threads(2)
def run(test_suit):
now=time.strftime("%Y-%m-%d %H_%M_%S")
result = BeautifulReport(test_suit)
result.report(filename=now+'report.html', description='测试报告', log_path='report')
if __name__ == "__main__":
# 用例集合
cases = add_case()
print(cases)
for i in cases:
print(i)
run(i)
'''
#不能删除,多个报告
if __name__=="__main__":
addr='D:/python/RMP_AutoTest/bbs/test_case/'
a=['mutilbox','gpcs']
for i in range(0,len(a)):
print(i,len(a),addr+a[i])
now=time.strftime("%Y-%m-%d %H_%M_%S")
fileName="D:/python/RMP_AutoTest/bbs/report/"+now+"result.html"
fp=open(fileName,'wb')
runner=HTMLTestRunner(stream=fp,
title=a[i]+u"测试",
description=u"常用环境"
)
discover=unittest.defaultTestLoader.discover(addr+a[i],pattern='*_only.py',top_level_dir=None)
#discover=unittest.TestLoader().discover('D:/python/RMP_AutoTest/bbs/test_case')
#discover=unittest.defaultTestLoader.discover('D:\\python\\RMP_AutoTest\\bbs\\TestCase',pattern='*_only.py')
runner.run(discover)
fp.close()
'''
'''
可以使用:
if __name__=="__main__":
addr='D:/python/RMP_AutoTest/rmp/'
addr_report=addr+'report/'
addr_test=addr+'testCase/test/'
a={'only_test':'干配测算自动化测试用例','only_test2':'干配测算自动化测试用例2'}#新增目录需要手动添加
now=time.strftime("%Y-%m-%d %H_%M_%S")
fileName=addr_report+now+"result.html"
fp=open(fileName,'wb')
print(len(a))
i=0
for key in a:
i=1+i
global discover,runner
#print(i,len(a),addr_test+a[i])
#discover=unittest.defaultTestLoader.discover(addr+a[i],pattern='*only.py',top_level_dir=None)
discover=unittest.defaultTestLoader.discover(addr_test+key,pattern='*sta.py',top_level_dir=None)
#discover=unittest.TestLoader().discover('D:/python/RMP_AutoTest/bbs/test_case')
#discover=unittest.defaultTestLoader.discover('D:\\python\\RMP_AutoTest\\bbs\\TestCase',pattern='*_only.py')
runner=HTMLTestRunner(stream=fp,
title=str(i)+'.自动化测试模块:'+a[key],
description=u"测试用例详情"
)
runner.run(discover)
fp.close()
'''
''''
if __name__=="__main__":
addr='D:/python/RMP_AutoTest/rmp/'
addr_report=addr+'report/'
addr_test=addr+'testCase/test/'
a={'only_test':'干配测算自动化测试用例','only_test2':'干配测算自动化测试用例2'}#新增目录需要手动添加
now=time.strftime("%Y-%m-%d %H_%M_%S")
fileName=addr_report+now+"result.html"
fp=open(fileName,'wb')
print(len(a))
i=0
for key in a:
i=1+i
global discover,runner
#print(i,len(a),addr_test+a[i])
#discover=unittest.defaultTestLoader.discover(addr+a[i],pattern='*only.py',top_level_dir=None)
discover=unittest.defaultTestLoader.discover(addr_test+key,pattern='*sta.py',top_level_dir=None)
#discover=unittest.TestLoader().discover('D:/python/RMP_AutoTest/bbs/test_case')
#discover=unittest.defaultTestLoader.discover('D:\\python\\RMP_AutoTest\\bbs\\TestCase',pattern='*_only.py')
runner=HTMLTestRunner(stream=fp,
title='自动化测试模块:',
description=u"测试用例详情" )
runner.run(discover)
fp.close()
'''''