3.python接口自动化ddt数据驱动

一、数据驱动参数文件Params.json

 


{
    "账号错误,密码错误": {"account": "admindsa", "password": "123456d","result": "账号或者密码错误"},
    "账号正确,密码错误": {"account": "admin", "password": "123","result": "账号或者密码错误"},
    "账号错误,密码正确": {"account": "admins", "password": "123456","result": "账号或者密码错误"},
    "账号正确,密码正确": {"account": "admin", "password": "123456","result": "登录成功"}

}

二、测试代码

 

from time import sleep

import requests, unittest, ddt


@ddt.ddt
class TestLogin(unittest.TestCase):
    # 初始化
    def setUp(self):
        self.url = 'http://110.191.238.12:12010/api/ih/login'

    # 调用requests中的post 方法
    @ddt.unpack
    @ddt.file_data(r'C:\workspace\Api\Conf\Params.json')
    def testLogin(self, account, password, result):
        datass = {"account": account, "password": password}
        print(datass)
        r = requests.post(self.url, json=datass)

        print(r.json())
        response = r.json()['message']
        self.assertEqual(result, response)
        sleep(1)

    def tearDown(self):
        pass


if __name__ == "__main__":
    unittest.main()

 

三、测试报告

3.python接口自动化ddt数据驱动_第1张图片

你可能感兴趣的:(Python接口自动化,接口自动化数据驱动,python中的ddt)