1、创建csv文件,写入对应接口和参数还有请求方式,将文件放在data文件夹中
2、创建文件去读取csv内容,我们在读取时需要用切片来将前面的文字去除前面的字段
import csv
class Testcxv:def test_csv(self):itme = []c = csv.reader(open('../data/接口.csv'))for csv_i in c:itme.append(csv_i) #将前面对应的标题去掉使用切片的方式itme = itme[1:3]return itme
t = Testcxv()
print(t.test_csv())
3、创建文件需要去执行接口进行返回状态码
import requests
from readdata.readdata import Testcxv
t = Testcxv()
lists = t.test_csv()
item = []
class TestRqerCsv:def test_csv(self):for csv_i in lists:if csv_i[2] == 'get':r = requests.get(url=csv_i[0],params=csv_i[1])item.append(r.status_code)print(r.status_code)else:r = requests.post(url=csv_i[0],data=csv_i[1])item.append(r.status_code)print(r.status_code)return itemt1 = TestRqerCsv()
print(t1.test_csv())
4、创建文件来编写我们单元测试和生成测试报告
import pytest,allure,os
from test_case.quercsv import TestRqerCsv
t = TestRqerCsv()
lists = t.test_csv()
class Test_csv:def test_csv(self):for csv_i in lists:assert csv_i == 200if __name__ == '__main__':pytest.main(['--alluredir', 'report/result', 'test_csv.py'])split = 'allure ' + 'generate ' + './report/result ' + '-o ' + './report/html ' + '--clean'os.system(split)
5、在右边会出出现一个文件夹点击index文件进行浏览器访问