逐步完善中…本篇记录使用csv管理测试数据

 

目录

1、读取csv

2、应用

 

 

1、读取csv

使用csv模块读取csv文件,使用reader方法读取csv文件

csv_file = open(file_path, mode="r")
csv_data = csv.reader(csv_file) 

2、应用

文件第一行放参数,通过取下标拿到每一行参数对应的值,第二行及以下放测试数据,每一次取一行

读取时,跳过第一行

is_header=True
for row in self.csv_data:
if is_header:
is_header=False
continue

通过取下标,每一个参数对应每一行的某一个值

            data1=row[1]
            data2=row[2]
            data3=row[3]
            expect=row[0]

完整case脚本

from m_module.m_addtopic_api  import *
import unittest
from common.read_csv import *

class testLogin(unittest.TestCase):
    def setUp(self):
        self.add=Topicadd()
        self.m=csvGet()
        csv_file='D:\\jp\\jpress_api\\test_data\\add_data.csv'
        self.csv_data=self.m.read_csv(csv_file)
        # print(self.csv_data)

    def test_login(self):
        is_header=True
        for row in self.csv_data:
            if is_header:
                is_header=False
                continue
            data1=row[1]
            data2=row[2]
            data3=row[3]
            expect=row[0]
            print(data1,data2,data3,expect)
            m=self.add.add(data1,data2,data3)
            print(m)
            m2=is_addtopic_success(m)
            # print(m2)
            self.assertEqual(bool(expect),m2)
    def tearDown(self):
        pass

if __name__=="__main__":
    unittest.main()

 

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-07-06
  • 2022-12-23
  • 2021-08-02
猜你喜欢
  • 2022-01-29
  • 2021-07-21
  • 2021-11-02
  • 2021-08-31
  • 2022-02-06
  • 2021-11-08
  • 2021-10-07
相关资源
相似解决方案