From cfb6395bc4a6c13c48b1da20047467bb8cd2c418 Mon Sep 17 00:00:00 2001 From: Albert Safin <38052075+betapl3b@users.noreply.github.com> Date: Thu, 6 Oct 2022 15:06:16 +0300 Subject: [PATCH] Add @allure.manual decorator to simplify ALLURE_MANUAL=True label setting (#688) * Added a decorator to simplify ALLURE_MANUAL=True label usage. Added tests for "allure.manual" decorator * Add dynamic `manual` label Co-authored-by: skhomuti --- .../examples/label/manual/allure_manual.rst | 16 ++++++++++++++ .../test/acceptance/label/manual/__init__.py | 0 .../acceptance/label/manual/manual_test.py | 21 +++++++++++++++++++ allure-python-commons/allure.py | 4 +++- allure-python-commons/src/_allure.py | 9 ++++++++ allure-python-commons/src/types.py | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 allure-pytest/examples/label/manual/allure_manual.rst create mode 100644 allure-pytest/test/acceptance/label/manual/__init__.py create mode 100644 allure-pytest/test/acceptance/label/manual/manual_test.py diff --git a/allure-pytest/examples/label/manual/allure_manual.rst b/allure-pytest/examples/label/manual/allure_manual.rst new file mode 100644 index 00000000..c189d710 --- /dev/null +++ b/allure-pytest/examples/label/manual/allure_manual.rst @@ -0,0 +1,16 @@ +Test manual label +------------- + +By default, ``ALLURE_MANUAL`` label is not set. + +Usage of ``allure.manual`` decorator. + + >>> import allure + + + >>> @allure.manual + ... def test_manual(): + ... pass + + >>> def test_manual_dynamic(): + ... allure.dynamic.manual() diff --git a/allure-pytest/test/acceptance/label/manual/__init__.py b/allure-pytest/test/acceptance/label/manual/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/allure-pytest/test/acceptance/label/manual/manual_test.py b/allure-pytest/test/acceptance/label/manual/manual_test.py new file mode 100644 index 00000000..a04a315b --- /dev/null +++ b/allure-pytest/test/acceptance/label/manual/manual_test.py @@ -0,0 +1,21 @@ +from hamcrest import assert_that +from allure_commons_test.report import has_test_case +from allure_commons_test.label import has_label + + +def test_allure_manual_label(executed_docstring_path): + """ ./examples/label/manual/allure_manual.rst """ + assert_that(executed_docstring_path.allure_report, + has_test_case("test_manual", + has_label("ALLURE_MANUAL", True) + ) + ) + + +def test_allure_manual_label_dynamic(executed_docstring_path): + """ ./examples/label/manual/allure_manual.rst """ + assert_that(executed_docstring_path.allure_report, + has_test_case("test_manual_dynamic", + has_label("ALLURE_MANUAL", True) + ), + ) diff --git a/allure-python-commons/allure.py b/allure-python-commons/allure.py index 9d6c99f0..58f2891f 100644 --- a/allure-python-commons/allure.py +++ b/allure-python-commons/allure.py @@ -10,6 +10,7 @@ from allure_commons._allure import Dynamic as dynamic from allure_commons._allure import step from allure_commons._allure import attach +from allure_commons._allure import manual from allure_commons.types import Severity as severity_level from allure_commons.types import AttachmentType as attachment_type @@ -35,5 +36,6 @@ 'dynamic', 'severity_level', 'attach', - 'attachment_type' + 'attachment_type', + 'manual' ] diff --git a/allure-python-commons/src/_allure.py b/allure-python-commons/src/_allure.py index 565ac955..32025c47 100644 --- a/allure-python-commons/src/_allure.py +++ b/allure-python-commons/src/_allure.py @@ -70,6 +70,10 @@ def id(id): return label(LabelType.ID, id) +def manual(fn): + return label(LabelType.MANUAL, True)(fn) + + def link(url, link_type=LinkType.LINK, name=None): return safely(plugin_manager.hook.decorate_as_link(url=url, link_type=link_type, name=name)) @@ -140,6 +144,10 @@ def parent_suite(parent_suite_name): def sub_suite(sub_suite_name): Dynamic.label(LabelType.SUB_SUITE, sub_suite_name) + @staticmethod + def manual(): + return Dynamic.label(LabelType.MANUAL, True) + def step(title): if callable(title): @@ -170,6 +178,7 @@ def impl(*a, **kw): args = list(map(lambda x: represent(x), a)) with StepContext(self.title.format(*args, **params), params): return func(*a, **kw) + return impl diff --git a/allure-python-commons/src/types.py b/allure-python-commons/src/types.py index d2fef791..321a7f0c 100644 --- a/allure-python-commons/src/types.py +++ b/allure-python-commons/src/types.py @@ -31,6 +31,7 @@ class LabelType(str): ID = 'as_id' FRAMEWORK = 'framework' LANGUAGE = 'language' + MANUAL = 'ALLURE_MANUAL' class AttachmentType(Enum):