一、测试用例用excel管理,存放地址:C:\Users\wangli\PycharmProjects\Test\test\files\apiCase.xls
二、代码实现如下:
1、封装读取excel用例数据
2、Pytest装饰器@pytest.mark.parametrize('参数名',list)实现登录模块2条测试用例数据驱动
import pytest,xlrd,os,requests,json
#获取excel用例数据
def get_case_data():
case_path = os.path.join(os.path.dirname(__file__), r'files\apiCase.xls')
book = xlrd.open_workbook(case_path)
sheet = book.sheet_by_name('sheet1名字')
case = []
for i in range(0, sheet.nrows):
if sheet.row_values(i)[0] == 'C端登录' and sheet.row_values(i)[3]=='YES':
case.append(sheet.row_values(i))
return case
class Test(object):
def setup_class(self):
pass
def teardown_class(self):
pass
#调用获取测试用例数据