参数化测试应用及测试报告产出
api_case运行所有的excel用例:
处理警告:
网页报告产出:
run_all_case.py
import os
import unittest
from utils import HTMLTestReportCN
from utils.config_utils import local_config
current_path = os.path.dirname(__file__)
case_path = os.path.join( current_path,'..','testcases')
result_path = os.path.join( current_path,'..',local_config.REPORT_PATH )
def load_testcase():
discover = unittest.defaultTestLoader.discover(start_dir=case_path,
pattern='test_api_case.py',
top_level_dir=case_path)
all_case_suite = unittest.TestSuite()
all_case_suite.addTest( discover )
return all_case_suite
result_dir = HTMLTestReportCN.ReportDirectory(result_path)
result_dir.create_dir('P3P4接口自动化测试报告_')
report_html_path = HTMLTestReportCN.GlobalMsg.get_value('report_path')
report_html_obj = open( report_html_path,'wb' )
runner = HTMLTestReportCN.HTMLTestRunner(stream=report_html_obj,
title='P3P4接口自动化测试报告',
description='数据驱动+关键字驱动测试框架学习',
tester='P3P4')
runner.run( load_testcase() )
report_html_obj.close()
test_api_case.py
import os
import unittest
import warnings
import paramunittest
from utils.testcase_data_utils import TestcaseDataUtils
from utils.requests_utils import RequestsUtils
test_case_lists = TestcaseDataUtils().convert_testcase_data_to_list()
@paramunittest.parametrized(
*test_case_lists
)
class TestApiCase(paramunittest.ParametrizedTestCase):
def setUp(self) -> None:
warnings.simplefilter('ignore',ResourceWarning)
def setParameters(self, case_id, case_step):
self.case_id = case_id,
self.case_step = case_step
def test_api_case(self):
self._testMethodName = self.case_step[0].get('测试用例编号')
self._testMethodDoc = self.case_step[0].get('测试用例名称')
test_result = RequestsUtils().request_by_step(self.case_step)
self.assertTrue( test_result['check_result'] )
if __name__=='__main__':
unittest.main(verbosity=2)
以上是 参数化测试应用及测试报告产出 的全部内容, 来源链接: utcz.com/a/76275.html