日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

DDT驱动

發(fā)布時間:2024/1/17 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DDT驱动 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

下載ddt并安裝

Pip install ddt

或者官網(wǎng)下載安裝

http://ddt.readthedocs.io/en/latest/

https://github.com/txels/ddt

DDT的使用

DDT包含類的裝飾器ddt和兩個方法裝飾器data(直接輸入測試數(shù)據(jù)),file_data(可以從json或者yaml中獲取測試數(shù)據(jù))

只有yaml和yml結尾的文件以yaml形式上傳,其他情況下默認為json

通常情況下,data中的數(shù)據(jù)按照一個參數(shù)傳遞給測試用例,如果data中含有多個數(shù)據(jù),以元組,列表,字典等數(shù)據(jù),需要自行在腳本中對數(shù)據(jù)進行分解或者使用unpack分解數(shù)據(jù)

@data(a,b)

那么a和b各運行一次用例

@data([a,d],[c,d])

如果沒有unpack,那么[a,b]當成一個參數(shù)傳入用例運行

如果有unpack,那么[a,b]被分解開,按照用例中的兩個參數(shù)傳遞

@file_data(filename)

對于json的文件,每一個json元素按照一個用例運行,可以依照python分解元組,列表或者字典的方式分解傳入

import unittest
from ddt import ddt,data,file_data,unpack

@ddt
class demotest(unittest.TestCase):
def setup(self):
print "this is the setup"

@data(2,3)
def testb(self,value):
print value
print "this is test b"

@data([2,3],[4,5])
def testa(self,value):
print value
print "this is test a"

@data([[1,7], 3], [4, 5])
@unpack
def testc(self, first,second):
print first
print second
print "this is test c"

@file_data('d:/data_dic.json')
def test_dic(self,value):
print value
print 'this is dic'

@file_data('d:/data.yml')
def test_yml(self, value):
print value
print 'this is yml'

def teardown(self):
print "this is the down"

if __name__ == '__main__':
unittest.main()
#suite=unittest.TestLoader.getTestCaseNames(demotest)
#suite = unittest.TestLoader().loadTestsFromTestCase(demotest)
#unittest.TextTestRunner(verbosity=2).run(suite)

轉載于:https://www.cnblogs.com/jt925/p/10195972.html

總結

以上是生活随笔為你收集整理的DDT驱动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。