一。数据结构:列表,数据字典,json串
二。文件:txt文件 csv文件 excel文件
三。数据库DDT:数据库连接 数据库提取
四。参数化 @pytest.mark.parametrize @pytest.fixture
一。数据结构
数据字典;
# 字典读取 # 方法1:读取key for key in userinfo.keys(): print(key) # 方法2:读取value for val in userinfo.values(): print(val) # 方法3:读取所有内容 for k in userinfo: print(k,userinfo[k])
json串
# 例子:json文件操作 import json # 读取json文件,用json.load()方法转换成字典格式,再去读取.如果json文件里面有汉字,记得该编码为encoding='utf-8'否则乱码 jsonfile=open('interface.json','r',encoding='utf-8') # print(jsonfile) # print(type(jsonfile)) # 转换数据类型 jsondict=json.load(jsonfile) #print(type(jsondict)) # 提取json文件中的内容 # 目标找到item里面的内容 for data in jsondict['item']: # print(data['name']) # 对于多层级的内容,逐层去找 for d in data['request']['body']['formdata']: # print(d) for key in d: print(key,d[key])
二,文件
2.1 txt文件的读取
打开文件: file=open('文件名.txt','r',encoding='uft-8')
读取文件内容:con=file.read()
写入文件内容:file.write('写入的内容')
关闭文件:file.close
处理完文件后,有2中方法可