厕所

来源:互联网 发布:人工智能 高校 编辑:程序博客网 时间:2024/04/19 15:06

coding=utf-8

import unittest
import sys
sys.path.append(r’./ars’)
from common import HTMLTestRunner
import os,time

from apscheduler.scheduler import Scheduler

from common import mailutil

from conf import config
import logging
logging.basicConfig()

”’
参数配置
”’
script_prefix = ‘test’ #脚本名称前缀

testcase_excle_path = r”E:\workspace\ATF\src\wifi.xlsx” #测试用例所在的路径

version = ‘PayGateway V1.0.0’ #项目版本信息
caselist = r’./ars’ #测试脚本所在的目录

def createSuite(pattern):
testunit = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(caselist, pattern=pattern, top_level_dir=None)
#discover 方法筛选出来的用例,循环添加到测试套件中
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
return testunit

def runtest():
alltestname = createSuite(script_prefix+”*.py”)

now = time.strftime('%Y-%m-%d-%H_%M_%S',time.localtime(time.time()))reportpath = os.getcwd().split("testcase")[0] + "\\report\\"#判断report目录是否存在if (os.path.exists(reportpath)) != True:    os.makedirs(reportpath)filename = reportpath+now+"_result.html"fp = file(filename,'wb')title = version + u"测试报告"runner = HTMLTestRunner.HTMLTestRunner(    stream=fp,    title=title,    description=u'用例执行情况:',

execelfile =testcase_excle_path,

version=version

)#执行测试用例runner.run(alltestname)#发送邮件

subject = title

mailutil.sendEmail(config.authInfo, config.fromAdd, config.toAdd,

config.ccAdd, subject, config.plainText,

filename, filename)

if name == ‘main‘:
runtest()

sched = Scheduler()

sched.daemonic = False

#定时执行

sched.add_cron_job(runtest,day_of_week=’mon-sat’, hour=’‘, minute=’‘,second=’*/30’)

sched.start()

0 0
原创粉丝点击