python 数据驱动ddt使用,需要调用下面的代码,请挨个方法调试,把不用的注释掉

#!/usr/bin/env/python
# -*- coding: utf-8 -*-
# @Time    : 2018/12/15 15:27

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
    }
}

  

posted @ 2019-02-22 14:28  ADChen  阅读(514)  评论(0编辑  收藏  举报