zoukankan      html  css  js  c++  java
  • ddt学习笔记

    ddt安装
    Pip install ddt

    ddt的使用
    导入
    from ddt import ddt,data,file_data

    说明:
    @data(a,b)

    表示a和b各运行一次用例

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

    如果没有unpack,那么[a,b]当成一个参数传入用例运行

    如果有unpack,那么[a,b]被分解开,按照用例中的两个参数传递

    @file_data(filename)

    对于json的文件,每一个json元素按照一个用例运行,可以依照python分解元组,列表或者字典的方式分解传入支持yaml

    例子
    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([2, 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)

    ps 使用发现方法中有循环时ddt数据看起来是最外层循环
  • 相关阅读:
    内置函数zip,map,even
    异常处理
    requests模块(请求接口)
    网络编程之urllib
    cookie/session区别
    测试环境搭建流程
    接口开发01--mock接口
    操作Redis--hash/key-value
    操作excel--xlwt/xlrd/xlutils模块
    可变对象 不可变对象 浅拷贝 深拷贝
  • 原文地址:https://www.cnblogs.com/lisi01/p/11157675.html
Copyright © 2011-2022 走看看