zoukankan      html  css  js  c++  java
  • python3.6+requests实现接口自动化7

    逐步完善中…本篇记录使用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()
  • 相关阅读:
    Zend Studio 9.0.2破解文件和注册码下载
    shell之netstat命令
    shell之arp命令
    Linux网络运维相关
    Linux静态ip设置及一些网络设置
    shell之进程
    shell之小知识点
    软连接与硬链接
    shell之dialog提示窗口
    Linux特殊权限位
  • 原文地址:https://www.cnblogs.com/weizhideweilai/p/13333761.html
Copyright © 2011-2022 走看看