最后我们总的执行文件来调用所有的接口测试案例自动运行,也方便和后面的CI进行整合。代码如下:
#coding=utf-8
__author__ = "Fighter Lu"
import unitTests,os,time
from JieKou.config.HTMLTestRunner import HTMLTestRunner
def allTest():
'''获取tesTcase下面的所有测试模块'''
suite = unitTests.defaultTestLoader.discover(
start_dir=os.path.join(os.path.dirname(__file__),'testCase'),
pattern='test*.py',
top_level_dir=None
)
return suite
def getNowtime():
'''获取当前时间'''
return time.strftime("%Y_%m_%d %H_%M_%S")
def run():
'''主函数入口'''
fp=open(os.path.join(os.path.dirname(__file__),'report',getNowtime() + 'report.html'),'wb')
HTMLTestRunner(stream=fp,
title='接口自动化测试报告',
description='基于python语言的接口自动化测试实战').run(allTest())
if __name__ == '__main__':
run()