Skip to content

Commit b7720d0

Browse files
authored
robot severity (via #268)
1 parent 912bbe0 commit b7720d0

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

allure-robotframework/src/listener/robot_listener.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from allure_commons.utils import now, uuid4, md5, host_tag
88
from allure_commons.logger import AllureFileLogger
99
from allure_commons.types import AttachmentType, LabelType, LinkType
10+
from allure_commons.types import Severity
1011
from allure_commons.utils import platform_label
1112
from robot.libraries.BuiltIn import BuiltIn
1213
from allure_robotframework.types import RobotKeywordType, RobotLogLevel
@@ -108,6 +109,8 @@ def stop_current_test(self, name, attributes):
108109
test.statusDetails = StatusDetails(message=attributes.get('message'))
109110
test.description = attributes.get('doc')
110111
last_link = list(self.links.values())[-1] if self.links else None
112+
if attributes.get(Severity.CRITICAL, 'no') == 'yes':
113+
test.labels.append(Label(name=LabelType.SEVERITY, value=Severity.CRITICAL))
111114
if last_link:
112115
test.links.append(Link(LinkType.LINK, last_link, 'Link'))
113116
test.stop = now()

allure-robotframework/test/library/test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from functools import partial
22
from hamcrest import assert_that
3-
from hamcrest import not_
3+
from hamcrest import not_, anything
44
from allure_commons_test.report import has_test_case
55
from allure_commons_test.result import has_description
66
from allure_commons_test.result import has_step
@@ -10,6 +10,7 @@
1010
from allure_commons_test.result import has_status_details
1111
from allure_commons_test.result import with_message_contains
1212
from allure_commons_test.result import has_attachment
13+
from allure_commons_test.label import has_severity
1314
from allure_commons_test.label import has_tag
1415
from allure_commons_test.container import has_container
1516
from allure_commons_test.container import has_before, has_after
@@ -53,6 +54,16 @@ def should_has_status(allure_report, item_matcher, status):
5354
assert_that(allure_report, status_matcher())
5455

5556

57+
def should_has_severity(allure_report, test_case_matcher, severity):
58+
severity_matcher = partial(test_case_matcher, has_severity, severity)
59+
assert_that(allure_report, severity_matcher())
60+
61+
62+
def should_not_has_severity(allure_report, test_case_matcher):
63+
severity_matcher = partial(test_case_matcher, not_, has_severity, anything)
64+
assert_that(allure_report, severity_matcher())
65+
66+
5667
def should_has_step(allure_report, item_matcher, step):
5768
step_matcher = partial(item_matcher, has_step, step)
5869
assert_that(allure_report, step_matcher())
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
*** Settings ***
2+
Library ./library/run.py
3+
Library ./library/test.py
4+
5+
6+
*** Variables ***
7+
${TC_SEVERITY} | *Test Cases* | | |\n
8+
... | Demo Test Case Severity - Alpha | [Tags] | alpha |\n
9+
... | | No Operation | |\n
10+
... | | | |\n
11+
... | Demo Test Case Severity - Bravo | [Tags] | bravo |\n
12+
... | | No Operation | |\n
13+
14+
15+
*** Test Cases ***
16+
Test Case Severity Critical
17+
${tmp_dir}= Make Temp Dir
18+
${test_case_dir}= Make Dir ${tmp_dir} test
19+
${test_case}= Make Test Case ${test_case_dir} step.robot ${TC_SEVERITY}
20+
${allure_report}= Robot Run With Allure ${tmp_dir} ${test_case} critical=alpha
21+
${tc_matcher}= Should Has Test Case ${allure_report} Demo Test Case Severity - Alpha
22+
Should Has Severity ${allure_report} ${tc_matcher} critical
23+
${tc_matcher}= Should Has Test Case ${allure_report} Demo Test Case Severity - Bravo
24+
Should Not Has Severity ${allure_report} ${tc_matcher}
25+
26+
Test Case Severity Noncritical
27+
${tmp_dir}= Make Temp Dir
28+
${test_case_dir}= Make Dir ${tmp_dir} test
29+
${test_case}= Make Test Case ${test_case_dir} step.robot ${TC_SEVERITY}
30+
${allure_report}= Robot Run With Allure ${tmp_dir} ${test_case} noncritical=alpha
31+
${tc_matcher}= Should Has Test Case ${allure_report} Demo Test Case Severity - Alpha
32+
Should Not Has Severity ${allure_report} ${tc_matcher}
33+
${tc_matcher}= Should Has Test Case ${allure_report} Demo Test Case Severity - Bravo
34+
Should Has Severity ${allure_report} ${tc_matcher} critical

0 commit comments

Comments
 (0)