def test_main(cases): #cases, get_db # 此处的cases入参来自与 conftest.py 文件中 cases函数,与直接使用 @pytest.mark.parametrize # 有着差不多的效果 # 发送请求 response, expect, sql = BaseRequest.send_request(cases) # 执行sql # DataProcess.handle_sql(sql, get_db) # 断言操作 DataProcess.assert_result(response, expect)
class TestApi: @classmethod def run(cls): if os.path.exists('../report'): shutil.rmtree(path='../report') logger.add(logfile, enqueue=True, encoding='utf-8') logger.info('开始测试...') pytest.main(args=[f'--alluredir={report}/data']) os.system(f'allure generate {report}/data -o {report}/html --clean') logger.success('报告已生成') @pytest.mark.parametrize('case', cases) def test_main(self, case, get_db): # 发送请求 response, expect, sql = BaseRequest.send_request(case) # 执行sql DataProcess.handle_sql(sql, get_db) # 断言操作 DataProcess.assert_result(response, expect)
def test_main(cases): # 不使用数据库功能 # 发送请求 response, expect, sql = BaseRequest.send_request(cases) # 断言操作 DataProcess.assert_result(response, expect)
def test_main(self, case): response, expect = BaseRequest.send_request(case) # 断言操作 DataProcess.assert_result(response, expect)