把下面代码请求进行封装,class TestDepartmentInfo: @allure.feature('科室管理相关API') @allure.title('删除科室信息') def test_delete_Department_info(self): list_delete_Department_info = read_excel(r'../api/testcase/addDepartmentInfo.xlsx') method = list_delete_Department_info[0, 3] url = default_url()+list_delete_Department_info[0, 4] for a in range(len(account_type())): # 根据账号类型的个数设置外层循环 headers = { 'Content-Type': 'application/json;charset=UTF-8', 'Authorization': get_real_token()[a] } for b in range(len(list_delete_Department_info)): # 根据用例的个数设置内层循环 data = eval(list_delete_Department_info[b, 7]) res = requests.request(method=method, url=url, headers=headers, json=data) # 断言匹配以及输出断言失败后的具体信息:响应信息+url+账号类型+用例名称+请求参数 check.equal(res.json()['code'], eval(list_delete_Department_info[b, a+8])['code'], str(res.json())+'\n'+url+' '+account_type()[a]+':'+list_delete_Department_info[b, 2]+' '+str(data))
时间: 2023-05-16 14:04:29 浏览: 91
将以下代码进行封装:
class TestDepartmentInfo:
@allure.feature('科室管理相关API')
@allure.title('删除科室信息')
def test_delete_Department_info(self):
list_delete_Department_info = read_excel(r'../api/testcase/addDepartmentInfo.xlsx')
method = list_delete_Department_info[0, 3]
url = default_url() list_delete_Department_info[0, 4]
for a in range(len(account_type())):
封装后的代码如下:
class TestDepartmentInfo:
@allure.feature('科室管理相关API')
@allure.title('删除科室信息')
def test_delete_Department_info(self):
list_delete_Department_info = read_excel(r'../api/testcase/addDepartmentInfo.xlsx')
method = list_delete_Department_info[0, 3]
url = default_url() list_delete_Department_info[0, 4]
for a in range(len(account_type())):
# 封装的代码
pass
其中,封装的代码部分需要根据具体需求进行编写。
阅读全文