一、文件目录结构如下图
二、data.yaml文件内容如下
Login_data:
- test_login_001: {"phone":"13488834010", "passwd":"159357", "get_mess":"成功","expect_message":"登录成功", "tag":1}
- test_login_002: {"phone":" 13488834010", "passwd":"159357", "get_mess":"成功","expect_message":"登录成功", "tag":1}
- test_login_003: {"phone":"13488834010 ", "passwd":"159357", "get_mess":"成功","expect_message":"登录成功", "tag":1}
- test_login_006: {"phone":"13488834010", "passwd":"000000", "get_mess":"错误","expect_message":"密码错误!"}
- test_login_008: {"phone":" ", "passwd":"000000", "get_mess":"请输入","expect_message":"请输入手机号码"}
- test_login_010: {"phone":"133333333331", "passwd":"000000", "get_mess":"不存在","expect_message":"账号不存在!"}
- test_login_011: {"phone":"1333333333", "passwd":"00//代码效果参考:http://www.zidongmutanji.com/bxxx/325850.html
0000", "get_mess":"不存在","expect_message":"账号不存在!"}- test_login_012: {"phone":"18888888888", "passwd":"000000", "get_mess":"不存在","expect_message":"账号不存在!"}
三、readyaml.py为从data目录下data.yaml中读取数据并存放到list中的代码
import yaml
from pathlib import Path
def readyaml(dataname):
"""
:param dataname: yaml文件名称
:return: list
"""
# 获取当前文件所在的路径
p = Path(file)
print("打印看看p:", p)
# 将当前目录的爷爷目录下的data下的dataname文件拼成了datapath
datapath = p.parent.parent.joinpath("data", dataname)
with open(datapath,"rb") as f:
yamldata = yaml.safe_load(f)
datalist = 【】
for i in yamldata.get("Login_data"):
for j in i.values():
datalist.append((j.get("phone"),j.get("passwd")))
return datalist
if name == //代码效果参考:http://www.zidongmutanji.com/zsjx/417653.html
' main':readyaml(dataname='data.yaml')
print(readyaml(dataname="data.yaml"))