Skip to content

Commit dddd28f

Browse files
authored
added allure.labels deco for robotframework (via #487)
1 parent 1ad01cd commit dddd28f

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

allure-pytest-bdd/test/pytest_bdd_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@given(parsers.parse("feature file {name} with content:\n\"\"\"\n{feature}\n\"\"\""))
66
def feature_definition(feature, testdir, name="example"):
7-
testdir.makefile(".feature".format(name=name), **dict([(name, feature)]))
7+
testdir.makefile("{name}.feature".format(name=name), **dict([(name, feature)]))
88
pass
99

1010

allure-python-commons/src/mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ def __hash__(self):
102102
return hash(self.label.name)
103103
return hash(repr(self))
104104

105-
return sorted([wl.label for wl in set([Wl(l) for l in reversed(labels)])])
105+
return sorted([wl.label for wl in set([Wl(label) for label in reversed(labels)])])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import allure
3+
4+
5+
@allure.label('layer', 'UI')
6+
def open_browser_with_ui_layer():
7+
pass
8+
9+
10+
def add_custom_label(label_type, *labels):
11+
allure.dynamic.label(label_type, *labels)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
.. code:: robotframework
3+
4+
*** Settings ***
5+
Library ./labels_library.py
6+
*** Test Case ***
7+
Test Case With Custom Labels
8+
[Setup] Open Browser With UI Layer
9+
Add Custom Label stand Alpha Beta

allure-robotframework/src/listener/allure_listener.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ def _report_messages(self, messages):
195195
self.lifecycle.attach_data(uuid=uuid4(), body=attachment, name='Keyword Log',
196196
attachment_type=AttachmentType.HTML)
197197

198+
@allure_commons.hookimpl
199+
def decorate_as_label(self, label_type, labels):
200+
def deco(func):
201+
def wrapper(*args, **kwargs):
202+
self.add_label(label_type, labels)
203+
func(*args, **kwargs)
204+
return wrapper
205+
return deco
206+
207+
@allure_commons.hookimpl
208+
def add_label(self, label_type, labels):
209+
with self.lifecycle.update_test_case() as case:
210+
for label in labels if case else ():
211+
case.labels.append(Label(label_type, label))
212+
198213
@allure_commons.hookimpl
199214
def attach_data(self, body, name, attachment_type, extension):
200215
self.lifecycle.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension)

allure-robotframework/test/label/testcase_bdd_label.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Library ../test_allure_library.py
55

66
*** Test Case ***
77
Run Without options
8-
${allure_report} Run Robot With Allure examples/label/
8+
${allure_report} Run Robot With Allure examples/label
99
${test_case} Should Has Test Case ${allure_report} Test Cases With BDD Labels
1010
Should Has Label ${test_case} epic Tag
1111
Should Has Label ${test_case} feature Label
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*** Settings ***
2+
Library ../run_robot_library.py
3+
Library ../test_allure_library.py
4+
5+
6+
*** Test Case ***
7+
Run Without options
8+
${allure_report} Run Robot With Allure examples/label/testcase_custom_labels.rst
9+
${test_case} Should Has Test Case ${allure_report} Test Case With Custom Labels
10+
Should Has Label ${test_case} layer UI
11+
Should Has Label ${test_case} stand Alpha
12+
Should Has Label ${test_case} stand Beta

0 commit comments

Comments
 (0)