一、yaml文件用途、结构、数据类型
yaml用途:
- 配置文件
- 编写测试用例
yaml数据结构:
- Map对象(dict)
- 数组(list)
mode的写入方式 mode=" "
值 | 含义 |
---|---|
r | 读取模式 |
w | 写模式 |
a | 追加模式 |
b | 二进制模式(和其他模式一起使用,比如rb,wb等) |
+ | 读/写模式,(和其他模式一起使用,入r+,w+,a+等) |
yaml读取方式
def read_yaml():
with open(os.getcwd()+"/extract.yaml") as f:
#Loader=yaml.FullLoader 固定写法
value = yaml.load(stream=f,Loader=yaml.FullLoader)
return value
yaml写入方式
def write_yaml(data):
with open((os.getcwd()+"/extract.yaml"),mode="a") as f:
#允许unicode编码
yaml.dump(data, stream=f,allow_unicode=True)
yaml清空方式
#清空yaml文件(extract.yaml)
def clear_yaml():
with open((os.getcwd()+"/extract.yaml"),mode="w") as f:
# f.truncate() 清空模式
f.truncate()
二、pytest用例管理框架
接口自动化框架文档
数据驱动装饰器
@pytest.mark.parametrize(args1,args2)
args1 : 参数名
args2 : 参数值
三、python结合allure生成报告
1.在pytest.ini加入命令
--alluredir = ./temps --clear-alluredir
2.生成allure报告
os.system("allure generate ./temps -o -reports --clear)