#!/usr/bin/env/python # -*- coding: utf-8 -*- # @Time : 2018/12/15 15:27 # @Author : ChenAdong # @Email : aiswell@foxmail.com import unittest import ddt lst = [1, 2, 3] dic = {"userName": "chen"} tur = (1, 2, 3) s = {1, 2, 3} @ddt.ddt class Test(unittest.TestCase): @ddt.data(*lst) def test_list(self, data): print("test_list") print(data) print("==================") @ddt.data(*dic) def test_dictionary(self, data): print("test_dic") print(data) print("==================") @ddt.file_data("ddt_test001.json") def test_file(self, key): print(key) @ddt.file_data("ddt_test.json") @ddt.unpack def test_file(self, start, end, value): print(start, end, value) if __name__ == "__main__": unittest.main()
ddt_test001.json
{ "name": "chen", "password": 123 }
ddt_test.json
{ "positive_integer_range": { "start": 0, "end": 2, "value": 1 }, "negative_integer_range": { "start": -2, "end": 0, "value": -1 }, "positive_real_range": { "start": 0.0, "end": 1.0, "value": 0.5 }, "negative_real_range": { "start": -1.0, "end": 0.0, "value": -0.5 } }