首页 > Web开发 > 详细

unittest生成测试报告(HTMLTestRunner)

时间:2018-02-24 17:49:36      阅读:296      评论:0      收藏:0      [点我收藏+]

# coding:utf-8
import unittest
import os
import HTMLTestRunner

# python2.7要是报编码问题,就加这三行,python3不用加

import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)

# 用例路径
case_path = os.path.join(os.getcwd(), "case")
# 报告存放路径
report_path = os.path.join(os.getcwd(), "report")
def all_case():
    discover = unittest.defaultTestLoader.discover(case_path,
                                                    pattern="test*.py",
                                                    top_level_dir=None)
    print(discover)
    return discover

if __name__ == "__main__":
    # runner = unittest.TextTestRunner()
    # runner.run(all_case())

    # html报告文件路径
    report_abspath = os.path.join(report_path, "result.html")
    fp = open(report_abspath, "wb")
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
                                           title=u‘自动化测试报告,测试结果如下:‘,
                                           description=u‘用例执行情况:‘)

    # 调用add_case函数返回值
    runner.run(all_case())
    fp.close()

unittest生成测试报告(HTMLTestRunner)

原文:https://www.cnblogs.com/chukun/p/8466887.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!