ddt Ui 案例2

准备用例文件:testcase1.py

 

testcase2.py

 

import ddt
import  unittest
from HTMLTestRunner import HTMLTestRunner
import random
import string
import time

def suiteList(testPath):
    discover = unittest.defaultTestLoader.discover(testPath, pattern='test*.py', top_level_dir=None)
    List=[suite for suite in discover]

    return List


def run(suite,htmlPath):
    with open(htmlPath, 'wb') as f:
            runner = HTMLTestRunner(stream=f, title="ddt report", description="测试报告:", verbosity=2)
            runner.run(suite)


def randDigit():
    stamp=str(int(time.time()*1000000))
    # list= random.sample(string.digits,random.randint(4,5))
    # res=''.join(list)+"_"+stamp
    return stamp


@ddt.ddt
class Test(unittest.TestCase):
    test_data=suiteList(testPath=r'./')

    @classmethod
    def setUpClass(cls):
        pass
    @classmethod
    def tearDownClass(cls):
        pass

    @ddt.data(*test_data)
    def test_run(self,value):
        run(value,htmlPath=r'./{}report.html'.format(randDigit()))
        print(time.asctime())
if __name__ == '__main__':
    unittest.main()

  

 

 

posted @ 2019-03-31 14:08  不带R的墨菲特  阅读(400)  评论(0编辑  收藏  举报