日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

關(guān)于pytest結(jié)合csv模塊實(shí)現(xiàn)csv格式的數(shù)據(jù)驅(qū)動(dòng)問題_python

作者:FamilyYan ? 更新時(shí)間: 2022-07-27 編程語(yǔ)言

一、什么是數(shù)據(jù)驅(qū)動(dòng)測(cè)試

DDT:data drive test
準(zhǔn)備一組數(shù)據(jù),通過寫一個(gè)測(cè)試用例,不同的數(shù)據(jù)進(jìn)行迭代。

二、csv文件承載數(shù)據(jù)

CSV:Comma Separated Values

csv文件就是逗號(hào)分隔的文本文件。
使用python中的csv模塊來(lái)處理csv文件
結(jié)合pygtest的參數(shù)化處理方式來(lái)實(shí)現(xiàn)ddt

三、csv數(shù)據(jù)驅(qū)動(dòng)示例

首先創(chuàng)建一個(gè)csv的file:

zhangsan,lisi,wangwu
tom,rose,lili

然后創(chuàng)建一個(gè)test_csv.py模塊

# -*- coding: utf-8 -*-
# @Time: 2022/5/29 4:20 下午
# @Author: wcystart
# @File: test_csv.py
# @description:
import pytest
import csv
def get_data():
    with open("test.csv") as f:
        lst = csv.reader(f)
        my_data = []
        for row in lst:
            my_data.extend(row) 
        return my_data
@pytest.mark.parametrize('name', get_data())
def test01(name):
    print(name)
if __name__ == '__main__':
   pytest.main(['-vs', 'test_csv.py'])
運(yùn)行結(jié)果;
test_csv.py::test01[zhangsan] zhangsan
PASSED
test_csv.py::test01[lisi] lisi
PASSED
test_csv.py::test01[wangwu] wangwu
PASSED
test_csv.py::test01[tom] tom
PASSED
test_csv.py::test01[rose] rose
PASSED
test_csv.py::test01[lili] lili
PASSED

原文鏈接:https://blog.csdn.net/qq_37982823/article/details/125032413

欄目分類
最近更新