ddt Ui 案例2

时间:2022-04-05 04:43:21

准备用例文件:testcase1.py

ddt  Ui 案例2

testcase2.py

ddt  Ui 案例2

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()

  ddt  Ui 案例2

ddt  Ui 案例2

ddt  Ui 案例2