1.数据构造获取我就不写了直接以test_data=[ ] 构造一个简单数据建模。实际你从哪里获取根据情况excel也好yaml也罢
2.用例套件处理,报告生成处理
import ddt
import unittest
from HTMLTestRunner_cn import HTMLTestRunner
import os
test_data=[1,2,3] def run(value): print(value) def suites(testPath):
discover = unittest.defaultTestLoader.discover(testPath, pattern='test_ddtapi.py', top_level_dir=None)
return discover def makeHtml(htmlPath,suite):
with open(htmlPath, 'wb') as f:
runner = HTMLTestRunner(stream=f, title="ddt report", description="测试报告:", verbosity=0)
runner.run(suite)
def main(): testPath=os.getcwd()
suite=suites(testPath)
htmlPath=r'C:\Users\Administrator\PycharmProjects\Supro\lib\report\ddtTest.html'
makeHtml(htmlPath,suite) @ddt.ddt
class TestDebug(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass @ddt.data(*test_data)
def test_run(self,value):
run(value) if __name__ == '__main__':
main()