ddt数据驱动在ui自动化中的应用二【多测师】

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 @ 2020-06-12 20:20  多测师_王sir  阅读(200)  评论(0编辑  收藏  举报