From e8d845ee45509d4b36614acc13638d8278920e22 Mon Sep 17 00:00:00 2001 From: sharovd Date: Mon, 7 Apr 2025 18:22:56 +0400 Subject: [PATCH 1/2] fix: set the correct detail message for passed steps (#835) --- .../src/listener/allure_listener.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/allure-robotframework/src/listener/allure_listener.py b/allure-robotframework/src/listener/allure_listener.py index 7c8bccfa..2a4d3a80 100644 --- a/allure-robotframework/src/listener/allure_listener.py +++ b/allure-robotframework/src/listener/allure_listener.py @@ -106,9 +106,10 @@ def start_before_fixture(self, name): fixture.name = name def stop_before_fixture(self, attributes, messages): - self._report_messages(messages) + status = attributes.get('status') + self._report_messages(status, messages) with self.lifecycle.update_before_fixture() as fixture: - fixture.status = get_allure_status(attributes.get('status')) + fixture.status = get_allure_status(status) fixture.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb) self.lifecycle.stop_before_fixture() @@ -117,9 +118,10 @@ def start_after_fixture(self, name): fixture.name = name def stop_after_fixture(self, attributes, messages): - self._report_messages(messages) + status = attributes.get('status') + self._report_messages(status, messages) with self.lifecycle.update_after_fixture() as fixture: - fixture.status = get_allure_status(attributes.get('status')) + fixture.status = get_allure_status(status) fixture.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb) self.lifecycle.stop_after_fixture() @@ -136,7 +138,7 @@ def start_test(self, name, attributes): container.children.append(uuid) def stop_test(self, _, attributes, messages): - self._report_messages(messages) + self._report_messages(attributes.get('status'), messages) if 'skipped' in [tag.lower() for tag in attributes['tags']]: attributes['status'] = RobotStatus.SKIPPED @@ -168,17 +170,21 @@ def start_keyword(self, name): step.name = name def stop_keyword(self, attributes, messages): - self._report_messages(messages) + status = attributes.get('status') + self._report_messages(status, messages) with self.lifecycle.update_step() as step: - step.status = get_allure_status(attributes.get('status')) + step.status = get_allure_status(status) step.parameters = get_allure_parameters(attributes.get('args')) step.statusDetails = StatusDetails(message=self._current_msg, trace=self._current_tb) self.lifecycle.stop_step() - def _report_messages(self, messages): + def _report_messages(self, status, messages): has_trace = BuiltIn().get_variable_value("${LOG LEVEL}") in (RobotLogLevel.DEBUG, RobotLogLevel.TRACE) attachment = "" + if status == RobotStatus.PASSED: + self._current_tb, self._current_msg = None, None + for message, next_message in zip_longest(messages, messages[1:]): name = message.get('message') level = message.get('level') From c00ae4484ff525844091040a3a5088dfa4eb3b19 Mon Sep 17 00:00:00 2001 From: sharovd Date: Thu, 24 Apr 2025 11:05:50 +0400 Subject: [PATCH 2/2] test: add covering issue #835 --- .../statuses/statuses_test.py | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/allure_robotframework/acceptance/robotframework_support/statuses/statuses_test.py b/tests/allure_robotframework/acceptance/robotframework_support/statuses/statuses_test.py index 2f65fd48..51d06aef 100644 --- a/tests/allure_robotframework/acceptance/robotframework_support/statuses/statuses_test.py +++ b/tests/allure_robotframework/acceptance/robotframework_support/statuses/statuses_test.py @@ -99,3 +99,73 @@ def test_steps_after_failed_are_skipped(docstring, robot_runner: AllureRobotRunn ) ) ) + + +def test_only_failed_steps_have_status_details(docstring, robot_runner: AllureRobotRunner): + """ + *** Variables *** + @{TEST_VALUES} 0 5 15 + + *** Test Cases *** + Test Case with mixed step results and status details + FOR ${value} IN @{TEST_VALUES} + Run Keyword And Ignore Error Should Be True ${value} > 10 + END + Log To Console Test message + """ + + robot_runner.run_robotframework( + suite_literals={"status.robot": docstring} + ) + + assert_that( + robot_runner.allure_results, + has_test_case( + "Test Case with mixed step results and status details", + has_step( + "${value} IN @{TEST_VALUES}", + has_step( + "${value} = 0", + has_step( + "BuiltIn.Run Keyword And Ignore Error", + has_step( + "BuiltIn.Should Be True", + with_status("failed"), + has_status_details( + with_message_contains("0 > 10' should be true."), + ) + ), + ), + ), + has_step( + "${value} = 5", + has_step( + "BuiltIn.Run Keyword And Ignore Error", + has_step( + "BuiltIn.Should Be True", + with_status("failed"), + has_status_details( + with_message_contains("5 > 10' should be true."), + ) + ), + ), + ), + has_step( + "${value} = 15", + has_step( + "BuiltIn.Run Keyword And Ignore Error", + has_step( + "BuiltIn.Should Be True", + with_status("passed"), + has_status_details({}) + ), + ), + ) + ), + has_step( + "BuiltIn.Log To Console", + with_status("passed"), + has_status_details({}) + ) + ) + )