需要用到@pytest.mark.parametrize()装饰器进行封装用例,调用getExceldatas()将读取出来的用例存放进装饰器,"data"为别名。如下图,分别请求头和参数做了为空判断,并将token插入到headers里面,这样每一个接口都能使用到登录返回的token,不用每次都去调用获取token。 第九步、利用allure生成测试报告。 allure是Pytest的...
2. 创建 hook pytest 加载 xlsx 文件后,会将表格中的每一行作为用例步骤,传递给 hook,通过定义pytest...
pytest是一个第三方库,用于执行python测试的框架,它收集已经用python代码编写好的用例进行执行,断言、参数化、筛选用例,测试夹具,结合allure生成HTML报告、用例失败重跑、日志记录,持续集成、动态生成测试标题等。 安装pip install pytest 1.参数化@pytest.mark.parametrize("变量名","引用的变量的值") 将data中的每...
框架理念:使用json文件编写测试用例,建一个脚本循环读取测试用例并执行,然后对比返回的接口和用例中的期望结果。将测试结果写入到一个excel表格中生成测试报告,最后使用发送邮件功能将测试报告发送到指定邮箱。其中对所有公共方法进行封装并放在common公共文件目录下。 四、各模块介绍 ---interface_test 项目文件夹目录 --...
1 import xlrd 2 import pytest 3 from testcase.basic import get_project_path 4 5 6 def get_excel_data(filename, sheet_name): 7 project_path = get_proje
# -*- coding: utf-8 -*- # @Time : 2023/6/13 20:47 # @Author : yanfa # @user : yanfa # @File : pytest_for_excel.py # @remark:pytest结合数据驱动excel """ """一、读取excel文件第三方库:xlrd xlwings pandas openpyxl:官方文档https://openpyxl.readthedocs.io/en/stable/""" """二...
一、Pytest 的下载安装 1、Python3 使用 pip install -U pytest 安装 2、查看 pytest 版本信息 pytest --version 3、pytest 用例的执行规则: ①测试文件以 test_xx.py 命名需要以 test_开头(或_test 结尾) ②测试类以 Test_开头,并且不能带有 init 方法 ...
import pytest def Read_Excel():# 将excel进行实例化 book = xlrd.open_workbook('E:\\web\\123.xlsx')# 通过下标方法读取sheet值 sheet = book.sheet_by_index(0)# 循环读取每行数据 return [dict(zip(sheet.row_values(0), sheet.row_values(row))) for row in range(1, sheet.nrows)]class ...
Python作为一种流行的编程语言,结合Requests、PyTest、Excel和Allure等工具,可以实现这一目标。首先,我们需要安装必要的Python库。可以通过pip命令安装Requests、PyTest和Allure: pip install requests pytest allure-pytest 接下来,我们创建一个名为test_api.py的测试文件,用于编写接口自动化测试用例。在test_api.py中,...
importxlrdimportsysdefread_excel_sheet(file,sheet_name):li=[]wb=xlrd.open_workbook(filename=file)# 打开文件# print(wb.sheet_names()) # 打印所有表格名字sheet_names=wb.sheet_names()# 获取所有工作表名称# 判断输入表名是否实际存在于excel内ifsheet_namenotinsheet_names:print('ERROR!!!\n输入表...