From 16283cebc6e16743d18a3754c75874cd2d5f96d3 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Thu, 29 Aug 2024 11:35:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=20(#197)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpfpt/utils/case_auto_generator.py | 16 ++++++---------- httpfpt/utils/request/case_data_parse.py | 7 +++---- httpfpt/utils/request/ids_extract.py | 6 ++++-- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/httpfpt/utils/case_auto_generator.py b/httpfpt/utils/case_auto_generator.py index a74338b..876e8a3 100644 --- a/httpfpt/utils/case_auto_generator.py +++ b/httpfpt/utils/case_auto_generator.py @@ -64,25 +64,21 @@ def auto_generate_testcases(rewrite: bool = False) -> None: testcase_func_name = 'test_' + testcase_func_name case_code = f'''#!/usr/bin/env python3 # -*- coding: utf-8 -*- -import allure import pytest -from httpfpt.common.send_request import send_request -from httpfpt.utils.request.case_data_parse import get_testcase_data +from common.send_request import send_request +from utils.request.case_data_parse import get_testcase_data -allure_data, ddt_data, ids = get_testcase_data(filename='{file_property[0]}') +ddt_data, ids = get_testcase_data(filename='{file_property[0]}') -@allure.epic(allure_data['epic']) -@allure.feature(allure_data['feature']) class {testcase_class_name}: """{testcase_class_name.replace('Test', '')}""" - @allure.story(allure_data['story']) - @pytest.mark.parametrize('data', ddt_data, ids=ids) - def {testcase_func_name}(self, data): + @pytest.mark.parametrize('case_data', ddt_data, ids=ids) + def {testcase_func_name}(self, case_data): """{create_file_root_name}""" - send_request.send_request(data) + send_request.send_request(case_data) ''' # 创建测试用例文件 tag = case_filename.split(httpfpt_config.PROJECT_NAME)[1].split(os.path.sep)[1:-1] diff --git a/httpfpt/utils/request/case_data_parse.py b/httpfpt/utils/request/case_data_parse.py index 2bff358..cabee90 100644 --- a/httpfpt/utils/request/case_data_parse.py +++ b/httpfpt/utils/request/case_data_parse.py @@ -119,7 +119,7 @@ def case_id_unique_verify() -> None: redis_client.rset(f'{redis_client.prefix}:case_id_list', str(all_case_id)) -def get_testcase_data(*, filename: str) -> tuple[dict, list, list]: +def get_testcase_data(*, filename: str) -> tuple[list, list]: """ 获取测试用例数据 @@ -138,7 +138,6 @@ def get_testcase_data(*, filename: str) -> tuple[dict, list, list]: if steps is None: raise RequestDataParseError(test_steps_error) - allure_data = case_data['config']['allure'] if isinstance(steps, dict): ids = get_ids(case_data) mark = get_testcase_mark(case_data) @@ -146,7 +145,7 @@ def get_testcase_data(*, filename: str) -> tuple[dict, list, list]: ddt_data = pytest.param(case_data, marks=[getattr(pytest.mark, m) for m in mark]) else: ddt_data = case_data - return allure_data, [ddt_data], ids + return [ddt_data], ids elif isinstance(steps, list): _ddt_data_list = [] marked_ddt_data_list = [] @@ -162,7 +161,7 @@ def get_testcase_data(*, filename: str) -> tuple[dict, list, list]: else: raise RequestDataParseError(test_steps_error) ids = get_ids(_ddt_data_list) - return allure_data, marked_ddt_data_list, ids + return marked_ddt_data_list, ids else: raise RequestDataParseError(f'请求测试用例数据文件 {filename} 格式错误, 请检查用例数据文件内容') diff --git a/httpfpt/utils/request/ids_extract.py b/httpfpt/utils/request/ids_extract.py index 240d614..5cbaf43 100644 --- a/httpfpt/utils/request/ids_extract.py +++ b/httpfpt/utils/request/ids_extract.py @@ -16,13 +16,15 @@ def get_ids(request_data: dict | list) -> list: try: if isinstance(request_data, dict): module = request_data['config']['module'] + name = request_data['test_steps']['name'] case_id = request_data['test_steps']['case_id'] - ids.append(f'module: {module}, case_id: {case_id}') + ids.append(f'module: {module}, name: {name}, case_id: {case_id}') else: for data in request_data: module = data['config']['module'] + name = data['test_steps']['name'] case_id = data['test_steps']['case_id'] - ids.append(f'module: {module}, case_id: {case_id}') + ids.append(f'module: {module}, name: {name}, case_id: {case_id}') except KeyError as e: raise RequestDataParseError('测试用例 ids 获取失败, 请检查测试用例数据是否符合规范: {}'.format(e)) return ids