目录
三、pytest之parametrize+yaml实现数据驱动
1.@pytest.mark.parametrize(args_name,args_value)
2.list列表:用一组-开头。同一个级别的-是同一个list
内容:Pytest测试框架之Allure报告定制以及Parametrize数据驱动
资源:python+requests+pytest接口自动化框架(1-4)-Python文档类资源-CSDN下载
一、Allure报告的定制
功能定制
左边:
@allure.epic("码尚教育接口自动化测试项目") #项目名称定制
@allure.feature("用户管理模块") #模块名称定制
@allure.story("码尚教育1") #接口名称定制
@allure.title("登录成功") #所有的接口用例使用一个标题
allure.dynamic.title(product+"注册成功") #用例的标题取决于数据
右边:
#严重程度
@allure.severity(allure.severity_level.BLOCKER)
BLOCKER:致命bug
CRITICAL:严重bug
NORMAL:一般
MINOR:提示
TRIVIAL:轻微bug
描述:
allure.dynamic.description("获取接口统一鉴权码token接口,此接口调用需)
链接:
接口访问地址:
bug链接:
测试用例连接:
@allure.link("接口访问地址")
@allure.issue("bug连接")
@allure.testcase("测试用例连接")
步骤:
for a in range(1,6):
with allure.step("执行第"+str(a)+"个步骤"):
pass
附件(web自动化错误截图,接口自动化文本信息)
#附件
with open(r"E:\\shu.png",mode="rb") as f:
content = f.read()
allure.attach(body=content,name="获取鉴权码错误截图",attachment_type=allu
re.attachment_type.PNG)
#文本
allure.attach(body="接口地址:XX",name="接口地址",attachment_type=allure.a
ttachment_type.TEXT)
@allure.epic("接口自动化测试项目") #项目名称定制
@allure.feature('测试模块') #模块名称定制
class TestApi:
@allure.story("天草接口") #接口名称定制
@allure.title("天草打印用例") # 所有的接口用例使用一个标题
@allure.severity(allure.severity_level.TRIVIAL) #严重程度
@allure.link("接口访问地址")
@allure.issue("bug连接")
@allure.testcase("测试用例连接")
def test_01_tian_cao(self):
allure.dynamic.description("用例描述,此接口打印天草") #用例描述
print("天草")
#步骤
for a in range(1, 6):
with allure.step("执行第" + str(a) + "个步骤"):
pass
#附件
allure.attach(body="接口地址:XX", name="接口地址", attachment_type=allure.attachment_type.TEXT)
二、Allure报告被局域网访问
reports文件夹单独拷贝出来无法访问
allure 需要容器
allure open ./reports
三、pytest之parametrize+yaml实现数据驱动
1.@pytest.mark.parametrize(args_name,args_value)
![](https://i-blog.csdnimg.cn/blog_migrate/a208e34a4b7e60781e7b323b8e66196a.png)
2.yaml文件
1.map对象:键:(空格)值。
2.list列表:用一组-开头。同一个级别的-是同一个list
- name1: 百里
3.纯量(scalars):单个的、不可再分的值
操作:安装 pip install pyyaml
![](https://i-blog.csdnimg.cn/blog_migrate/32c4a02aa1cac9f84f1370840a3d5e08.png)
3.接口自动化
书写用例的YAML文件
请求接口测试
@allure.story("获取token接口") # 接口名称定制
@pytest.mark.parametrize("args_name", read_yaml("./testcases/wx/get_token.yaml"))
def test_get_token(self,args_name):
names = args_name['name']
methods = args_name['request']['method']
urls = args_name['request']['url']
datas = args_name['request']['data']
headers = args_name['request']['headers']
res = requests.get(url=urls, params=datas)
print(res.json())
运行: