diff --git a/allure-pytest-bdd/test/pytest_bdd_steps.py b/allure-pytest-bdd/test/pytest_bdd_steps.py index 599e4e9a..3260d9b3 100644 --- a/allure-pytest-bdd/test/pytest_bdd_steps.py +++ b/allure-pytest-bdd/test/pytest_bdd_steps.py @@ -4,7 +4,7 @@ @given(parsers.parse("feature file {name} with content:\n\"\"\"\n{feature}\n\"\"\"")) def feature_definition(feature, testdir, name="example"): - testdir.makefile(".feature".format(name=name), **dict([(name, feature)])) + testdir.makefile("{name}.feature".format(name=name), **dict([(name, feature)])) pass diff --git a/allure-python-commons/src/mapping.py b/allure-python-commons/src/mapping.py index 07905e3d..61ec79d3 100644 --- a/allure-python-commons/src/mapping.py +++ b/allure-python-commons/src/mapping.py @@ -102,4 +102,4 @@ def __hash__(self): return hash(self.label.name) return hash(repr(self)) - return sorted([wl.label for wl in set([Wl(l) for l in reversed(labels)])]) + return sorted([wl.label for wl in set([Wl(label) for label in reversed(labels)])]) diff --git a/allure-robotframework/examples/label/labels_library.py b/allure-robotframework/examples/label/labels_library.py new file mode 100644 index 00000000..7ac7c297 --- /dev/null +++ b/allure-robotframework/examples/label/labels_library.py @@ -0,0 +1,11 @@ + +import allure + + +@allure.label('layer', 'UI') +def open_browser_with_ui_layer(): + pass + + +def add_custom_label(label_type, *labels): + allure.dynamic.label(label_type, *labels) diff --git a/allure-robotframework/examples/label/testcase_custom_labels.rst b/allure-robotframework/examples/label/testcase_custom_labels.rst new file mode 100644 index 00000000..5ea84940 --- /dev/null +++ b/allure-robotframework/examples/label/testcase_custom_labels.rst @@ -0,0 +1,9 @@ + +.. code:: robotframework + + *** Settings *** + Library ./labels_library.py + *** Test Case *** + Test Case With Custom Labels + [Setup] Open Browser With UI Layer + Add Custom Label stand Alpha Beta diff --git a/allure-robotframework/src/listener/allure_listener.py b/allure-robotframework/src/listener/allure_listener.py index 9e2fd28d..d0e80527 100644 --- a/allure-robotframework/src/listener/allure_listener.py +++ b/allure-robotframework/src/listener/allure_listener.py @@ -195,6 +195,21 @@ def _report_messages(self, messages): self.lifecycle.attach_data(uuid=uuid4(), body=attachment, name='Keyword Log', attachment_type=AttachmentType.HTML) + @allure_commons.hookimpl + def decorate_as_label(self, label_type, labels): + def deco(func): + def wrapper(*args, **kwargs): + self.add_label(label_type, labels) + func(*args, **kwargs) + return wrapper + return deco + + @allure_commons.hookimpl + def add_label(self, label_type, labels): + with self.lifecycle.update_test_case() as case: + for label in labels if case else (): + case.labels.append(Label(label_type, label)) + @allure_commons.hookimpl def attach_data(self, body, name, attachment_type, extension): self.lifecycle.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension) diff --git a/allure-robotframework/test/label/testcase_bdd_label.robot b/allure-robotframework/test/label/testcase_bdd_label.robot index 60e0d443..5cb1c90a 100644 --- a/allure-robotframework/test/label/testcase_bdd_label.robot +++ b/allure-robotframework/test/label/testcase_bdd_label.robot @@ -5,7 +5,7 @@ Library ../test_allure_library.py *** Test Case *** Run Without options - ${allure_report} Run Robot With Allure examples/label/ + ${allure_report} Run Robot With Allure examples/label ${test_case} Should Has Test Case ${allure_report} Test Cases With BDD Labels Should Has Label ${test_case} epic Tag Should Has Label ${test_case} feature Label diff --git a/allure-robotframework/test/label/testcase_custom_labels.robot b/allure-robotframework/test/label/testcase_custom_labels.robot new file mode 100644 index 00000000..1a0d9bb1 --- /dev/null +++ b/allure-robotframework/test/label/testcase_custom_labels.robot @@ -0,0 +1,12 @@ +*** Settings *** +Library ../run_robot_library.py +Library ../test_allure_library.py + + +*** Test Case *** +Run Without options + ${allure_report} Run Robot With Allure examples/label/testcase_custom_labels.rst + ${test_case} Should Has Test Case ${allure_report} Test Case With Custom Labels + Should Has Label ${test_case} layer UI + Should Has Label ${test_case} stand Alpha + Should Has Label ${test_case} stand Beta