Python 接口测试的unittest 测试用例管理 2022-02-11(3)
参照:https://www.bilibili.com/video/BV1ju411f7ty?p=10
接上一篇学习笔记:https://www.cnblogs.com/ww-xiaowei/p/15883019.html
unittest 测试用例管理框架
import configparser import json import unittest from api_keyword.keyDemo import keyDemo from ddt import ddt,file_data '''创建1个unittest 测试用例管理框架''' '''仍然要用到config.ini login_testData.yaml keyDemo.py''' '''通过ddt实现yaml文件的读取''' @ddt class APICaseManager(unittest.TestCase): #测试用例 @file_data('../data/login.yaml') #yaml的测试数据以字典的形式传给function:**kwargs 这个关键字参数 def test_01_api_login(self,**kwargs): #获取配置文件的内容 conf=configparser.ConfigParser() conf.read('../config/config.ini') print(conf.get('DEFAULT','url')) #组装测试数据 url=conf.get('DEFAULT','url')+kwargs['path'] header=kwargs['headers'] data=json.dumps(kwargs['data']) #接口的测试 kd= keyDemo() res=kd.post(url=url,headers=header,param=data) print(res.text) if __name__ == '__main__': unittest.main(verbosity=2)
基于yaml文件拆分数据结构,这里yaml在之前的基础上稍作调整:它认为yaml的数据必须作为1个整体,因此在顶层加了1个key值
调整前:
path: /test/tenants/byLogin data: loginAccount: 86812393 password: 12393 headers: content-type: application/json clienttype: ANDROID appcode: IDP_PRO timezone: UTC+8 language: en_US version: 1.2.7
调整后:
login: path: /test/tenants/byLogin data: loginAccount: 86812393 password: 12393 headers: content-type: application/json clienttype: ANDROID appcode: IDP_PRO timezone: UTC+8 language: en_US version: 1.2.7
-----------------------------------------Have a good day!---------------------------------------------------------------------------------------------------

浙公网安备 33010602011771号