定义失败重跑机制

This commit is contained in:
遥爸 2023-03-10 11:12:43 +08:00
parent 4fdc37973a
commit 783cc24e6b
9 changed files with 32 additions and 15 deletions

View File

@ -62,4 +62,6 @@ lark:
webhook:
# 定义重跑参数
reruns: 3
reruns_delay: 3

View File

@ -150,5 +150,5 @@ platform_goods_total_05:
dependence_case_data:
assert:
status_code: 200
status_code: 404
sql:

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023-02-24 16:59:44
# @Time : 2023-03-10 11:03:09
import allure
@ -20,7 +20,8 @@ re_data = regular(str(TestData))
@allure.epic("上传通用接口")
@allure.feature("上传接口")
class TestUploadFile:
@pytest.mask.flaky(reruns=3, reruns_delay=3)
@allure.story("上传接口")
@pytest.mark.parametrize('in_data', eval(re_data), ids=[i['detail'] for i in TestData])
def test_upload_file(self, in_data, case_skip):

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023-02-24 16:59:45
# @Time : 2023-03-10 11:03:09
import allure
import pytest
@ -10,7 +9,7 @@ from utils.assertion.assert_control import Assert
from utils.requests_tool.request_control import RequestControl
from utils.read_files_tools.regular_control import regular
from utils.requests_tool.teardown_control import TearDownHandler
import pytest_rerunfailures
case_id = ['platform_index_01', 'platform_property_02', 'platform_goods_list_03', 'platform_goods_comment_04', 'platform_goods_total_05']
TestData = GetTestCase.case_data(case_id)
@ -22,6 +21,7 @@ re_data = regular(str(TestData))
class TestPlatformIndex:
@allure.story("商城模块")
@pytest.mark.flaky(reruns=3, reruns_delay=3)
@pytest.mark.parametrize('in_data', eval(re_data), ids=[i['detail'] for i in TestData])
def test_platform_index(self, in_data, case_skip):
"""

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023-02-24 16:59:45
# @Time : 2023-03-10 11:03:09
import allure
@ -20,7 +20,8 @@ re_data = regular(str(TestData))
@allure.epic("JekunAuto小程序接口")
@allure.feature("登录模块")
class TestLogin:
@pytest.mask.flaky(reruns=3, reruns_delay=3)
@allure.story("登录")
@pytest.mark.parametrize('in_data', eval(re_data), ids=[i['detail'] for i in TestData])
def test_login(self, in_data, case_skip):

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023-02-24 16:59:45
# @Time : 2023-03-10 11:03:09
import allure
@ -20,7 +20,8 @@ re_data = regular(str(TestData))
@allure.epic("JekunAuto小程序接口")
@allure.feature("登录模块")
class TestUserInfo:
@pytest.mask.flaky(reruns=3, reruns_delay=3)
@allure.story("用户信息")
@pytest.mark.parametrize('in_data', eval(re_data), ids=[i['detail'] for i in TestData])
def test_user_info(self, in_data, case_skip):

View File

@ -14,6 +14,9 @@ class NotificationType(Enum):
FEI_SHU = 4
# dataclass 提供一个简便的方式创建数据类, 默认实现__init__(), __repr__(), __eq__()方法.
# dataclass支持数据类型的嵌套
# 支持将数据设置为不可变
@dataclass
class TestMetrics:
""" 用例执行数据 """
@ -225,6 +228,7 @@ class AllureAttachmentType(Enum):
PDF = "pdf"
@unique
class AssertMethod(Enum):
"""断言类型"""
@ -244,3 +248,8 @@ class AssertMethod(Enum):
contained_by = 'contained_by'
startswith = 'startswith'
endswith = 'endswith'
class Reruns(BaseModel):
reruns: int
reruns_delay: int

View File

@ -40,7 +40,8 @@ def write_testcase_file(*, allure_epic, allure_feature, class_title,
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 设置为True的时候修改yaml文件的用例代码中的内容会实时更新
real_time_update_test_cases = conf_data['real_time_update_test_cases']
reruns = conf_data['reruns']
reruns_delay = conf_data['reruns_delay']
page = f'''#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : {now}
@ -63,7 +64,8 @@ re_data = regular(str(TestData))
@allure.epic("{allure_epic}")
@allure.feature("{allure_feature}")
class Test{class_title}:
@pytest.mark.flaky(reruns={reruns}, reruns_delay={reruns_delay})
@allure.story("{allure_story}")
@pytest.mark.parametrize('in_data', eval(re_data), ids=[i['detail'] for i in TestData])
def test_{func_title}(self, in_data, case_skip):

View File

@ -15,6 +15,7 @@ import urllib3
from requests_toolbelt import MultipartEncoder
from common.setting import ensure_path_sep
from utils.logging_tool.log_control import ERROR
from utils.other_tools.exceptions import ValueNotFoundError
from utils.other_tools.models import RequestType
from utils.logging_tool.log_decorator import log_decorator
from utils.mysql_tool.mysql_control import AssertExecution
@ -48,8 +49,8 @@ class RequestControl:
_data = self.__yaml_case.data
for key, value in ast.literal_eval(cache_regular(str(_data)))['data'].items():
file_data[key] = value
except KeyError:
...
except KeyError as exc:
raise ValueNotFoundError("{data}数据未找到请检查yaml文件是否添加") from exc
@classmethod
def multipart_data(