diff --git a/allure-python-commons/src/allure_commons/lifecycle.py b/allure-python-commons/src/allure_commons/lifecycle.py index f6a4ff33..bf071e4d 100644 --- a/allure-python-commons/src/allure_commons/lifecycle.py +++ b/allure-python-commons/src/allure_commons/lifecycle.py @@ -35,8 +35,7 @@ def _last_item_uuid(self, item_type=None): @contextmanager def schedule_test_case(self, uuid=None): - test_result = TestResult() - test_result.uuid = uuid or uuid4() + test_result = TestResult(uuid=uuid or uuid4()) self._items[test_result.uuid] = test_result yield test_result diff --git a/allure-python-commons/src/allure_commons/model2.py b/allure-python-commons/src/allure_commons/model2.py index a117948c..98112cc8 100644 --- a/allure-python-commons/src/allure_commons/model2.py +++ b/allure-python-commons/src/allure_commons/model2.py @@ -1,7 +1,8 @@ +from __future__ import annotations + from attr import attrs, attrib from attr import Factory - TEST_GROUP_PATTERN = "{prefix}-container.json" TEST_CASE_PATTERN = "{prefix}-result.json" ATTACHMENT_PATTERN = "{prefix}-attachment.{ext}" @@ -12,49 +13,49 @@ class TestResultContainer: file_pattern = TEST_GROUP_PATTERN - uuid = attrib(default=None) - name = attrib(default=None) - children = attrib(default=Factory(list)) - description = attrib(default=None) - descriptionHtml = attrib(default=None) - befores = attrib(default=Factory(list)) - afters = attrib(default=Factory(list)) - links = attrib(default=Factory(list)) - start = attrib(default=None) - stop = attrib(default=None) + uuid: str = attrib(default=None) + name: str | None = attrib(default=None) + children: list[str] = attrib(default=Factory(list)) + description: str | None = attrib(default=None) + descriptionHtml: str | None = attrib(default=None) + befores: list[TestBeforeResult] = attrib(default=Factory(list)) + afters: list[TestAfterResult] = attrib(default=Factory(list)) + links: list[Link] = attrib(default=Factory(list)) + start: int | None = attrib(default=None) + stop: int | None = attrib(default=None) @attrs class ExecutableItem: - name = attrib(default=None) - status = attrib(default=None) - statusDetails = attrib(default=None) - stage = attrib(default=None) - description = attrib(default=None) - descriptionHtml = attrib(default=None) - steps = attrib(default=Factory(list)) - attachments = attrib(default=Factory(list)) - parameters = attrib(default=Factory(list)) - start = attrib(default=None) - stop = attrib(default=None) + name: str | None = attrib(default=None) + status: str | None = attrib(default=None) + statusDetails: StatusDetails | None = attrib(default=None) + stage: str | None = attrib(default=None) + description: str | None = attrib(default=None) + descriptionHtml: str | None = attrib(default=None) + steps: list[TestStepResult] = attrib(default=Factory(list)) + attachments: list[Attachment] = attrib(default=Factory(list)) + parameters: list[Parameter] = attrib(default=Factory(list)) + start: int | None = attrib(default=None) + stop: int | None = attrib(default=None) @attrs class TestResult(ExecutableItem): file_pattern = TEST_CASE_PATTERN - uuid = attrib(default=None) - historyId = attrib(default=None) - testCaseId = attrib(default=None) - fullName = attrib(default=None) - labels = attrib(default=Factory(list)) - links = attrib(default=Factory(list)) - titlePath = attrib(default=Factory(list)) + uuid: str = attrib(default=None) + historyId: str | None = attrib(default=None) + testCaseId: str | None = attrib(default=None) + fullName: str | None = attrib(default=None) + labels: list[Label] = attrib(default=Factory(list)) + links: list[Link] = attrib(default=Factory(list)) + titlePath: list[str] = attrib(default=Factory(list)) @attrs class TestStepResult(ExecutableItem): - id = attrib(default=None) + id: str | None = attrib(default=None) @attrs @@ -69,37 +70,37 @@ class TestAfterResult(ExecutableItem): @attrs class Parameter: - name = attrib(default=None) - value = attrib(default=None) - excluded = attrib(default=None) - mode = attrib(default=None) + name: str = attrib(default=None) + value: str = attrib(default=None) + excluded: bool | None = attrib(default=None) + mode: str | None = attrib(default=None) @attrs class Label: - name = attrib(default=None) - value = attrib(default=None) + name: str = attrib(default=None) + value: str = attrib(default=None) @attrs class Link: - type = attrib(default=None) - url = attrib(default=None) - name = attrib(default=None) + type: str | None = attrib(default=None) + url: str = attrib(default=None) + name: str | None = attrib(default=None) @attrs class StatusDetails: - known = attrib(default=None) - flaky = attrib(default=None) - message = attrib(default=None) - trace = attrib(default=None) + known: bool | None = attrib(default=None) + flaky: bool | None = attrib(default=None) + message: str | None = attrib(default=None) + trace: str | None = attrib(default=None) @attrs class Attachment: - name = attrib(default=None) - source = attrib(default=None) - type = attrib(default=None) + name: str = attrib(default=None) + source: str = attrib(default=None) + type: str | None = attrib(default=None) class Status: diff --git a/allure-python-commons/src/allure_commons/types.py b/allure-python-commons/src/allure_commons/types.py index 43b8d5ed..42846942 100644 --- a/allure-python-commons/src/allure_commons/types.py +++ b/allure-python-commons/src/allure_commons/types.py @@ -1,7 +1,5 @@ from enum import Enum -ALLURE_UNIQUE_LABELS = ["severity", "thread", "host"] - class Severity(str, Enum): BLOCKER = "blocker" @@ -34,9 +32,11 @@ class LabelType(str): MANUAL = "ALLURE_MANUAL" -class AttachmentType(Enum): +ALLURE_UNIQUE_LABELS = [LabelType.SEVERITY, LabelType.THREAD, LabelType.HOST] - def __init__(self, mime_type, extension): + +class AttachmentType(Enum): + def __init__(self, mime_type: str, extension: str) -> None: self.mime_type = mime_type self.extension = extension @@ -66,7 +66,7 @@ def __init__(self, mime_type, extension): PDF = ("application/pdf", "pdf") -class ParameterMode(Enum): +class ParameterMode(str, Enum): HIDDEN = "hidden" MASKED = "masked" - DEFAULT = None + DEFAULT = "default"