码迷,mamicode.com
首页 > 其他好文 > 详细

BeautifulReport--适用于unittest自动化测试的可视化报告

时间:2018-09-02 01:56:55      阅读:3072      评论:0      收藏:0      [点我收藏+]

标签:就是   原因   cas   pytho   load   new   自动   python   add   

安装:

  因为是由大神分享的,可以直接在github<https://github.com/TesterlifeRaymond/BeautifulReport>上下载 git clone git@github.com:TesterlifeRaymond/BeautifulReport.git  download后,需要把包放到 D:\python3.6.5\Lib\site-packages 目录下,以备调用;

技术分享图片

 

使用:

  和HTMLTestRunner.py在运行case上稍有不同

import os
import time
import unittest
from BeautifulReport import BeautifulReport
from common.logger import Log
# from common.HTMLTestRunnerCN import HTMLTestRunner
from common import readConfig

now = time.strftime(%Y-%m-%d %H-%M-%S)


def add_case(case_path):
    """加载所有的测试用例"""
    discover = unittest.defaultTestLoader.discover(case_path, pattern=test*.py, top_level_dir=None)  # 定义discover方法的参数
    Log().info(测试用例:%s % discover)
    # HTMLTestRunner
    # testUnit = unittest.TestSuite()
    # discover方法筛选出来的用例,循环添加到测试套件中
    # for test_suite in discover:
    #     for test_case in test_suite:
    #         testUnit.addTests(test_case)
    # return testUnit

    # BeautifulReport
    return discover


def run_case(all_case, report_path):
    """执行所有测试用例,并把结果写入报告"""
    # HTMLTestRunner
    # report_abspath = os.path.join(report_path, now + ‘report.html‘)
    # fp = open(report_abspath, ‘wb‘)
    # runner = HTMLTestRunner(stream=fp, verbosity=2, title=readConfig.title, description=‘用例执行情况:‘)
    # runner.run(all_case)  # 调用add_case函数返回值

    # BeautifulReport
    result = BeautifulReport(all_case)
    result.report(filename=now + report.html, description=readConfig.title, log_path=report_path)
    Log().info(执行用例,生成HTML报告!)

if __name__ == __main__:
  case_path = os.path.abspath(os.path.dirname(__file__)) + \\case
  all_case = add_case(case_path)
  # 生成报告测试路径
  # report_path = os.path.abspath(os.path.dirname(__file__)) + ‘/report‘
  report_path = os.path.abspath(os.path.dirname(__file__)) + \\report
  run_case(all_case, report_path)

  不需要再添加case,直接返回获取到的所有用例即可;

html报告:

技术分享图片

 

  稍微修改了下生成的报告,增加了 用例错误 的展示和返回顶部的按钮;

  因为是跑的接口,所以没有使用  BeautifulReport 的截图功能,有机会再试... 

 

问题:

  在 用例描述 那里会显示:dict() -> new empty dictionary dict ,看了下,好像是在获取用例函数的文档字符串时,返回的就是这个,暂时没找到原因,只能先去掉了...有知道的大佬请指点下...

BeautifulReport--适用于unittest自动化测试的可视化报告

标签:就是   原因   cas   pytho   load   new   自动   python   add   

原文地址:https://www.cnblogs.com/changqing8023/p/9572181.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!