unittest 参数化调用添加到测试套中并生成测试报告

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#    @version : 0.0.1
#    @File    : 1111.py
#    @Time    : 2019/6/19 15:31
#    @Site    : 
#    @Software: PyCharm
#    @Author  : KANGXINWEN
#    @Author_email: singbogo@163.com
#    @description: 
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest


class TestCases(unittest.TestCase):

    def setUp(self):
        pass

    def action(self, arg1, arg2):
        print(arg1, arg2)

    @staticmethod
    def getTestFunc(arg1, arg2):
        def func(self):
            self.action(arg1, arg2)
        return func


def __generateTestCases(suite):
    arglists = [('arg11', 'arg12'), ('arg21', 'arg22'), ('arg31', 'arg32')]
    for args in arglists:
        setattr(TestCases, 'test_func_%s_%s' % (args[0], args[1]),
                TestCases.getTestFunc(*args))
    for args in arglists:
        test = 'test_func_%s_%s' % (args[0], args[1])
        suite.addTest(TestCases(test))




import os
from HTMLTestReport import HTMLTestRunner
from HTMLTestRunner_PY3 import HTMLTestRunner
BASE_PATH = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
REPORT_PATH = os.path.join(BASE_PATH, 'report')



def run():
    suite = unittest.TestSuite()
    __generateTestCases(suite)
    print("------" + str(suite))
    report_title = 'Example用例执行报告'
    desc = '用于展示修改样式后的HTMLTestRunner'
    report_file = 'ExampleReport.html'
    with open(report_file, 'wb') as report:
        runner = HTMLTestRunner(stream=report, title=report_title, description=desc)
        runner.run(suite)


if __name__ == '__main__':
    run()

HTMLTestRunner.py 文件下载: http://tungwaiyip.info/software/HTMLTestRunner.html

测试报告:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值