目前调用自己的两个接口,分别获取token(get)及获取用户信息(post)
新建common的package:存放用例数据文件或者共享配置的文件
新建testcase.py:存放用例
新建temp目录:存放allure生成的临时json
新建report目录:存放生成的报告
新建conftest.py:全局配置,部分用例的前后置等
新建all.py:main()方法单独存放
1.请求方式封装:
common下新建request_until.py文件
import pytest
import requests
class RequestUntil():
def send_request(self,method,url,data,**kwargs):
method = str(method).lower()
rep=""
if method == 'get':
rep = requests.request(method,url=url,params=data,**kwargs)
else:
rep = requests.request(method,url=url,data=data,**kwargs)
return rep.json()
2.yaml做数据驱动
a.common下新建yaml_until.py,负责将token写入一个yml文件,方便其他接口使用,以及负责 测试用例数据的读取 :
import os
import yaml
class YmalUntil():
#写入extract.yml文件
def write_token_extract(self,data):
print(self.__class__)
print("=======================lxj=================================")
print(os.getcwd())
print(data)
with open(os.getcwd()+"\extract.yml",mode