import requests
import pandas as pd
import pytest
import allure
@allure.epic("项目名称")
@allure.feature("模块名称")
@allure.story("接口名称")
@allure.title("用例标题")
@allure.description("用例描述")
def test_login():
with allure.step("步骤1:输入帐号"):
assert 1 == 1
with allure.step("步骤1:输入帐号"):
assert 2 == 2
def readcsv():
df = pd.read_excel("c.xlsx")
return df.to_dict(orient="records")
@pytest.mark.parametrize("case", readcsv())
def test_cases(case):
url=case["url"]
method=case["method"].upper()
params=case["params"]
if method == "GET":
resp=requests.get(url,params=params)
with allure.step("发送请求"):
allure.attach(f"{resp.content}+请求参数+{resp.json()}")
allure.dynamic.description(f"参数:{resp.url}\n响应:{resp.json()}")
elif method == "POST":
resp=requests.post(url,json=params)
with allure.step(f"发送请求{resp.json()}"):
allure.attach(f"{resp.content}+请求参数+{resp.json()}")
allure.dynamic.description(f"参数:{resp.url}\n响应:{resp.json()}")
assert resp.status_code == int(case["except"])
import allure
import pytest
import requests
@allure.epic("接口自动化测试项目")
@allure.feature("测试接口模块")
class TestDemoApi:
@allure.story("测试GET接口")
@allure.title("测试获取公共接口")
def test_get_api(self):
with allure.step("1. 准备请求地址"):
url = "https://httpbin.org/get"
with allure.step("2. 发送GET请求"):
res = requests.get(url)
with allure.step("3. 断言状态码=200"):
assert res.status_code == 200
with allure.step("4. 保存数据到报告"):
allure.attach(str(res.json()), "响应结果", allure.attachment_type.JSON)