request+pytest+allure

读取csv文件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
读取xslx文件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用Python + requests + pytest + allure的核心代码示例: ```python import requests import pytest import allure @allure.feature("接口测试") class TestAPI: @allure.story("测试接口1") def test_api1(self): url = "http://api.example.com/api1" headers = {"Content-Type": "application/json"} data = {"key": "value"} response = requests.post(url, headers=headers, json=data) assert response.status_code == 200 assert response.json()["result"] == "success" allure.attach(name="请求参数", body=str(data), attachment_type=allure.attachment_type.JSON) allure.attach(name="响应结果", body=str(response.json()), attachment_type=allure.attachment_type.JSON) @allure.story("测试接口2") def test_api2(self): url = "http://api.example.com/api2" headers = {"Content-Type": "application/json"} data = {"key": "value"} response = requests.post(url, headers=headers, json=data) assert response.status_code == 200 assert response.json()["result"] == "success" allure.attach(name="请求参数", body=str(data), attachment_type=allure.attachment_type.JSON) allure.attach(name="响应结果", body=str(response.json()), attachment_type=allure.attachment_type.JSON) if __name__ == "__main__": pytest.main(["-s", "-v", "--alluredir", "./allure-results"]) ``` 这段代码演示了如何使用Pythonrequests库发送HTTP请求,并结合pytestallure进行接口测试。其中,`test_api1`和`test_api2`是两个测试用例,分别发送POST请求到不同的接口,并对响应结果进行断言。使用allure的`attach`方法可以将请求参数和响应结果作为附件展示在测试报告中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值