ddt-数据驱动

Posted 1376402226-yuyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ddt-数据驱动相关的知识,希望对你有一定的参考价值。

import unittest
from ddt import ddt, data, unpack


@ddt
class FooTestCase(unittest.TestCase):

@data((3, 2), (4, 3), (5, 3))
@unpack
def test_tuples_extracted_into_arguments(self, first_value, second_value):
self.assertTrue(first_value > second_value)

@data([3, 2], [4, 3], [5, 3])
@unpack
def test_list_extracted_into_arguments(self, first_value, second_value):
self.assertTrue(first_value > second_value)

@unpack
@data({‘first‘: 1, ‘second‘: 3, ‘third‘: 2},
{‘first‘: 4, ‘second‘: 6, ‘third‘: 5})
def test_dicts_extracted_into_kwargs(self, first, second, third):
print(first, second, third)
self.assertTrue(first < third < second)


if __name__ == ‘__main__‘:
unittest.main(verbosity=2)































以上是关于ddt-数据驱动的主要内容,如果未能解决你的问题,请参考以下文章

Python+unittest+DDT实现的数据驱动测试

Python 中使用 ddt 来进行数据驱动,批量执行用例,修改ddt代码

Python ddt数据驱动

Python 之数据驱动工具:DDT

python - 数据驱动测试 - ddt

Python数据驱动(ddt)