pytest(一)csv数据驱动
一、csv数据驱动
- csv文件内容
1,1,2
3,6,9
100,200,3000
- csv数据驱动使用方法
import csv
import pytest
def get_csv():
with open("data.csv") as file:
raw = csv.reader(file)
data = []
for line in raw:
data.append(line)
# print(data) #[['1', '1', '2'], ['3', '6', '9'], ['100', '200', '3000']]
return data
def my_add(x, y):
result = x + y
return result
class TestWithCsv:
@pytest.mark.parametrize('x,y,expected',get_csv())
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_csv.py"])
- 运行结果
原文地址:https://blog.csdn.net/xu_jing_ya/article/details/144199802
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!