您的位置:首页 > 其它

unittest+tomorrow+BeautifulReport实现自动化测试的多线程

2019-06-12 18:40 2835 查看

前言
为了减少自动化执行的时间,准备引入多线程的概念来优化自动化框架。
环境必备:
1.python3.6:BeautifulReport不支持2.7
2.tomorrow:pip install tomorrow安装
3.•BeautifulReport : github下载后放到/Lib/site-packages/目录下。下载链接:https://github.com/TesterlifeRaymond/BeautifulReport

# -*- encoding:utf-8 -*-
import os
import time
from tomorrow import threads
import unittest
from BeautifulReport import BeautifulReport
curpath = os.path.dirname(os.path.realpath(__file__))
reportpath = os.path.join(curpath, 'report')
test_dir = './interface'

def add_case(test_dir):
discover = unittest.defaultTestLoader.discover(test_dir, pattern='*_test.py')
return discover

@threads(2)
def run_case(all_case):
print (all_case)
print("开始,现在时间是%s"%time.strftime("%Y-%m-%d %H_%M_%S"))
# '''执行所有的用例,并把结果写入测试报告'''
result =BeautifulReport(all_case)
result.report(filename='report.html', description='测试deafult报告', log_path='report')

if __name__ == "__main__":
cases = add_case(test_dir)
for i in cases:
run_case(i)
[测试报告截图]


备注:1.当多线程同时运行多个.py文件的用例时,测试报告中,报告汇总和饼状图区域的统计数据不准确。
2.调试代码时,要选取运行时间大于0.5s的案例,不然pycharm控制台打印会遗漏一些输出,会影响问题的定位。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: