#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'myy'
__date__ = '2021.03.18'
import ddt, unittest
@ddt.ddt
class MyTesting(unittest.TestCase):
def setUp(self) -> None:
print('test start')
# 传入的数据未被分解,正向用例
@ddt.data([1, 2, 3])
def test_not_unpack(self, data):
print(data)
self.assertEqual(data, [1, 2, 3])
# data中的数据被分解为3个参数
@ddt.data([3, 4, -1], [6, 7, 8])
@ddt.unpack
def test_unpack(self, a, b, diff):
print(a, b, diff)
actual = float(a)-float(b)
expected = float(diff)
self.assertEqual(actual, expected)
# 传入的参数未被分解,反向用例
@ddt.data([1, 2], [3, 4])
def test_not_unpack_error(self, a, b):
print(a)
self.assertEqual(a, b)
def tearDown(self) -> None:
print('test end')
if __name__ == '__main__':
unittest.main(verbosity=2)
unittest+ddt 自动化测试
最新推荐文章于 2024-09-04 20:18:34 发布