Bootstrap

python+pytest,参数化数据测试,读取csv的数据

read_excel()方法读取返回多少列,@pytest.mark.parametrize("username,password", read_excel())引号内就写多少个参数
def read_excel():
    xlsx = openpyxl.load_workbook("D:\pythonProjects\datauser.xlsx")
    sheet1 = xlsx['Sheet1']
    print(sheet1.max_row)  # 行
    print(sheet1.max_column)  # 列
    print('=======================================================')
    allList = []
    for row in range(1, sheet1.max_row + 1):
        rowlist = []
        for column in range(1, sheet1.max_column + 1):
            rowlist.append(sheet1.cell(row, column).value)
        allList.append(rowlist)
        print(allList)
    return allList


# 测试案例必须要以Test开头

class TestAddUser:
    @pytest.mark.parametrize("username,password", read_excel())
    def test_upload(self,username,password):
        print(username,password)

;