pytest(二)excel数据驱动

一、excel数据驱动

  1. excel文件内容
  2. excel数据驱动使用方法
python 复制代码
import openpyxl
import pytest

def get_excel():
    excel_obj = openpyxl.load_workbook("../pytest结合数据驱动-excel/data.xlsx")
    sheet_obj = excel_obj["Sheet1"]
    values = sheet_obj.values
    case_list = []

    for row in values:
        data = []
        if row[0] != 'A':
            for cell in row:
                data.append(cell)
            case_list.append(data)
    print(case_list)        #[[1, 1, 2], [3, 6, 9], [100, 200, 300]]
    return case_list


def my_add(x, y):
    # print(x,y)
    result = x + y
    return result

class TestWithExcel:
    @pytest.mark.parametrize('x,y,expected',get_excel())
    def test_add(self, x, y, expected):
        # print(x,y,expected)
        print(f"{x} + {y} = {expected}")
        assert my_add(int(x), int(y))== int(expected)


if __name__ == '__main__':
    pytest.main(["-s", "test_caseexcel.py"])
  1. 运行结果
相关推荐
weixin_445054724 分钟前
力扣刷题-热题100题-第35题(c++、python)
c++·python·leetcode
_x_w1 小时前
【17】数据结构之图及图的存储篇章
数据结构·python·算法·链表·排序算法·图论
pianmian11 小时前
arcgis几何与游标(1)
开发语言·python
冬天vs不冷1 小时前
SpringBoot条件注解全解析:核心作用与使用场景详解
java·spring boot·python
nanzhuhe2 小时前
python中参数前**的含义
开发语言·python
hello_ejb32 小时前
聊聊Spring AI Alibaba的PdfTablesParser
windows·python·spring
Kairo_012 小时前
秘密任务 2.0:如何利用 WebSockets + DTOs 设计实时操作
python
ghost1432 小时前
Python自学第2天:条件语句,循环语句
开发语言·python·学习
RunsenLIu2 小时前
基于Django实现的图书分析大屏系统项目
后端·python·django
小小福仔2 小时前
Python爬虫第四战(使用防盗链下载视频)
爬虫·python·音视频·反爬·防盗链referer