标签:登录 sheet 取值 unit 方法 def erb login pen
# 方法2:获取单元格的值,需要数据的时候根据单元格行列值进行取值,只使用数据较少的时候,不推荐 # 每次需要数据的时候再从磁盘读取--到内存--到CPU执行, # 运行速度:磁盘<内存<CPU,造成CPU等待,浪费资源 #1. get_data2.py from openpyxl import load_workbook class DoExcel: def __init__(self, file, sheet): self.file = file self.sheet = sheet self.sheet_obj = load_workbook(self.file)[self.sheet] def get_data(self, i, j): return self.sheet_obj.cell(i, j).value # 2. class_test2.py import unittest from API_AUTO.tools.http_request import HttpRequest class TestLogin(unittest.TestCase): def setUp(self): print("sart testing...") def tearDown(self): print("case done.") def __init__(self, methodName, url, method, data, expected): super(TestLogin, self).__init__(methodName) self.url = url self.method = method self.data = data self.expected = expected def test_api(self): res = HttpRequest().http_request(self.url, self.method, self.data) r = res.json()["info"] try: self.assertEqual(r, self.expected) except AssertionError as e: print("there is an error in the case {}".format(e)) raise e # 3. run.py # 测试套件 import unittest from para_2.get_data2 import DoExcel from para_2.class_test2 import TestLogin import HTMLTestRunner suite = unittest.TestSuite() case_data = DoExcel("data_2.xlsx", "sh2") for i in range(1, 6): suite.addTest(TestLogin("test_api", case_data.get_data(i, 1), case_data.get_data(i, 2), eval(case_data.get_data(i, 3)), case_data.get_data(i, 4))) with open("login_2.html", "wb") as file: runner = HTMLTestRunner.HTMLTestRunner(stream=file, verbosity=2, title="登录2测试报告", description="加油,你只要坚持今天就是成功") runner.run(suite)
表格测试数据如图:
标签:登录 sheet 取值 unit 方法 def erb login pen
原文地址:https://www.cnblogs.com/come202011/p/12230868.html