#!/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

测试报告:

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐