unittest-读取yaml文件
生活随笔
收集整理的這篇文章主要介紹了
unittest-读取yaml文件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
注:
(1)yaml文件詳解
yaml是一種數(shù)據(jù)格式,類似txt,excel,json
它只有兩種數(shù)據(jù)類型:
map對象(鍵值對,冒號后需要有空格)
list列表對象,以-開頭
讀取之后是一個不定長的字典形式 用不定長的參數(shù)接收**args
import unittest from ddt import ddt,data,unpack,file_data@ddt class TestApi(unittest.TestCase):# @file_data('yaml_06.yaml')# yaml_06.yml文件是[{"name":ddd,"testage":123},"name2":test2,"name3":test3]# 在yaml_06.yml文件中,相當于執(zhí)行三次測試用例,# 第一次獲取到的數(shù)據(jù)是name:....# 第二次獲取到的數(shù)據(jù)是name2: test2# 第三次獲取到的數(shù)據(jù)是name3:test3# 如果yaml文件以list形式開始,則key或者value值應(yīng)保持一致# 如:["name":ddd,","name2:test2,"name":test3] key保持一致 for instance:yaml_06_1.yaml# or [1,2,3,4] value類型保持一致'''yaml_06.yaml:- name: 1.獲取接口統(tǒng)一鑒權(quán)碼token接口request:method: geturl: https://www.baidu.comdata:grant_type: client_credentialappid: 114secret: 121443validate:-equals: 1-contains: "access_token"- name2: test2- name3: test3'''@file_data('yaml_06.yaml')def test_01_get_token(self, **kargs):print(kargs)# print(kargs['name']) # 此處會有錯誤,是第二次執(zhí)行此用例時,name關(guān)鍵字沒有# print(kargs[0]['request']['method'])# print(kargs[1]['name2'])'''yaml_06_1.yaml:- name: 1.獲取接口統(tǒng)一鑒權(quán)碼token接口request:method: geturl: https://www.baidu.comdata:grant_type: client_credentialappid: 114secret: 121443validate:-equals: 1-contains: "access_token"- name: test2- name: test3'''@file_data('yaml_06_1.yaml')def test_02_get_token(self,**kargs):print(kargs)print(kargs['name']) #此處會有錯誤,是第二次執(zhí)行此用例時,name關(guān)鍵字沒有# print(kargs[0]['request']['method'])# print(kargs[1]['name2'])'''yaml_06_2.yaml- 1- 2- 3- 4'''@file_data('yaml_06_2.yaml')def test_03_get_token(self, kargs):print(kargs) 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的unittest-读取yaml文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: opencv9-膨胀和腐蚀
- 下一篇: python二维图颜色函数_Python