Skip to content

Commit 68bbafe

Browse files
authored
Set the correct detail message for passed steps (fix #835) (#853)
1 parent 04a9655 commit 68bbafe

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

allure-robotframework/src/listener/allure_listener.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ def start_before_fixture(self, name):
106106
fixture.name = name
107107

108108
def stop_before_fixture(self, attributes, messages):
109-
self._report_messages(messages)
109+
status = attributes.get('status')
110+
self._report_messages(status, messages)
110111
with self.lifecycle.update_before_fixture() as fixture:
111-
fixture.status = get_allure_status(attributes.get('status'))
112+
fixture.status = get_allure_status(status)
112113
fixture.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb)
113114
self.lifecycle.stop_before_fixture()
114115

@@ -117,9 +118,10 @@ def start_after_fixture(self, name):
117118
fixture.name = name
118119

119120
def stop_after_fixture(self, attributes, messages):
120-
self._report_messages(messages)
121+
status = attributes.get('status')
122+
self._report_messages(status, messages)
121123
with self.lifecycle.update_after_fixture() as fixture:
122-
fixture.status = get_allure_status(attributes.get('status'))
124+
fixture.status = get_allure_status(status)
123125
fixture.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb)
124126
self.lifecycle.stop_after_fixture()
125127

@@ -136,7 +138,7 @@ def start_test(self, name, attributes):
136138
container.children.append(uuid)
137139

138140
def stop_test(self, _, attributes, messages):
139-
self._report_messages(messages)
141+
self._report_messages(attributes.get('status'), messages)
140142

141143
if 'skipped' in [tag.lower() for tag in attributes['tags']]:
142144
attributes['status'] = RobotStatus.SKIPPED
@@ -168,17 +170,21 @@ def start_keyword(self, name):
168170
step.name = name
169171

170172
def stop_keyword(self, attributes, messages):
171-
self._report_messages(messages)
173+
status = attributes.get('status')
174+
self._report_messages(status, messages)
172175
with self.lifecycle.update_step() as step:
173-
step.status = get_allure_status(attributes.get('status'))
176+
step.status = get_allure_status(status)
174177
step.parameters = get_allure_parameters(attributes.get('args'))
175178
step.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb)
176179
self.lifecycle.stop_step()
177180

178-
def _report_messages(self, messages):
181+
def _report_messages(self, status, messages):
179182
has_trace = BuiltIn().get_variable_value("${LOG LEVEL}") in (RobotLogLevel.DEBUG, RobotLogLevel.TRACE)
180183
attachment = ""
181184

185+
if status == RobotStatus.PASSED:
186+
self._current_tb, self._current_msg = None, None
187+
182188
for message, next_message in zip_longest(messages, messages[1:]):
183189
name = message.get('message')
184190
level = message.get('level')

tests/allure_robotframework/acceptance/robotframework_support/statuses/statuses_test.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,73 @@ def test_steps_after_failed_are_skipped(docstring, robot_runner: AllureRobotRunn
9999
)
100100
)
101101
)
102+
103+
104+
def test_only_failed_steps_have_status_details(docstring, robot_runner: AllureRobotRunner):
105+
"""
106+
*** Variables ***
107+
@{TEST_VALUES} 0 5 15
108+
109+
*** Test Cases ***
110+
Test Case with mixed step results and status details
111+
FOR ${value} IN @{TEST_VALUES}
112+
Run Keyword And Ignore Error Should Be True ${value} > 10
113+
END
114+
Log To Console Test message
115+
"""
116+
117+
robot_runner.run_robotframework(
118+
suite_literals={"status.robot": docstring}
119+
)
120+
121+
assert_that(
122+
robot_runner.allure_results,
123+
has_test_case(
124+
"Test Case with mixed step results and status details",
125+
has_step(
126+
"${value} IN @{TEST_VALUES}",
127+
has_step(
128+
"${value} = 0",
129+
has_step(
130+
"BuiltIn.Run Keyword And Ignore Error",
131+
has_step(
132+
"BuiltIn.Should Be True",
133+
with_status("failed"),
134+
has_status_details(
135+
with_message_contains("0 > 10' should be true."),
136+
)
137+
),
138+
),
139+
),
140+
has_step(
141+
"${value} = 5",
142+
has_step(
143+
"BuiltIn.Run Keyword And Ignore Error",
144+
has_step(
145+
"BuiltIn.Should Be True",
146+
with_status("failed"),
147+
has_status_details(
148+
with_message_contains("5 > 10' should be true."),
149+
)
150+
),
151+
),
152+
),
153+
has_step(
154+
"${value} = 15",
155+
has_step(
156+
"BuiltIn.Run Keyword And Ignore Error",
157+
has_step(
158+
"BuiltIn.Should Be True",
159+
with_status("passed"),
160+
has_status_details({})
161+
),
162+
),
163+
)
164+
),
165+
has_step(
166+
"BuiltIn.Log To Console",
167+
with_status("passed"),
168+
has_status_details({})
169+
)
170+
)
171+
)

0 commit comments

Comments
 (0)