python接口自动化测试三十六:数据驱动参数化之paramunittest

时间:2019-06-12
本文章向大家介绍python接口自动化测试三十六:数据驱动参数化之paramunittest,主要包括python接口自动化测试三十六:数据驱动参数化之paramunittest使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

官方文档
1.官方文档地址:https://pypi.python.org/pypi/ParamUnittest/
2.github源码下载地址:https://github.com/rik0/ParamUnittest

安装paramunittest:

字典格式

运行结果

import unittest
import paramunittest

@paramunittest.parametrized(
{'user': 'user1', 'password': 'password1', 'result': 'true'},
{'user': 'user2', 'password': 'password2', 'result': 'true'},
{'user': 'user3', 'password': 'password3', 'result': 'true'},
)
class TestDemo(unittest.TestCase):
def setParameters(self, user, password, result): # 与字典的key一一对应
self.user = user
self.password = password
self.result = result

def testCase(self):
print(f'user: {self.user}')
print(f'password: {self.password}')
print(f'result: {self.result}')
self.assertEqual('true', self.result)

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

元祖格式同理

测试数据与代码分离的使用:先获取所有测试数据(字典或者元祖格式),再传给装饰器

原文地址:https://www.cnblogs.com/zhongyehai/p/11009776.html