1.
from openpyxl import load_workbook class DoExcel: def __init__(self, file_name, sheet_name): self.file_name = file_name self.sheet_name = sheet_name self.sheet_obj = load_workbook(self.file_name)[self.sheet_name] self.max_row = self.sheet_obj.max_row self.max_column = self.sheet_obj.max_column def get_data(self, i, j): return self.sheet_obj.cell(i, j).value if __name__ == '__main__': value = DoExcel('test.xlsx', 'test').get_data(2, 1) print(value)
2.
import unittest from xxx.xxx.xxx import HttpRequest from xxx.xxx.xxx import DoExcel class TestHttp(unittest.TestCase): def setUp(self): pass def __init__(self, methodName, url, data, method, expected): super(TestHttp, self).__init__(methodName) self.url = url self.data = data self.method = method self.expected = expected def test_api(self): res = HttpRequest().http_request(self.url, self.data, self.method) try: self.assertEqual(self.expected, res.json()['code']) except AssertionError as e: print("'test_api's error is{}".format(e)) raise e def tearDown(self): pass if __name__ == '__main__': suite = unittest.TestSuite() t = DoExcel('test.xlsx', 'test') for i in range(2, t.max_row + 1): suite.addTest(TestHttp('test_api', t.get_data(i, 1), t.get_data(i, 2), t.get_data(i, 3), t.get_data(i, 4))) runner = unittest.TextTestRunner() runner.run(suite)