Skip to content

Commit

Permalink
Fixed SETUP / TEARDOWN keyword removing
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Jan 17, 2025
1 parent ac99746 commit 9e50c17
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Fixed
- SETUP / TEARDOWN keyword removing, by @HardNorth

## [5.6.1]
### Added
Expand Down
10 changes: 10 additions & 0 deletions examples/before_after/before_suite_with_steps_fail.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*** Settings ***
Suite Setup Log suite setup

*** Test Cases ***
My first test
Log My first test

*** Keywords ***
Log suite setup
Fail Suite setup step
25 changes: 15 additions & 10 deletions robotframework_reportportal/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) ->
suite.rp_item_id = self.service.start_suite(suite=suite, ts=ts)
self._add_current_item(suite)

def _log_data_removed(self, item_id: str, timestamp: str, message: str) -> None:
msg = LogMessage(message)
msg.level = "DEBUG"
msg.item_id = item_id
msg.timestamp = timestamp
self.__post_log_message(msg)

def _log_keyword_content_removed(self, item_id: str, timestamp: str) -> None:
self._log_data_removed(item_id, timestamp, REMOVED_KEYWORD_CONTENT_LOG)

@check_rp_enabled
def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
"""Finish started test suite at the ReportPortal.
Expand All @@ -420,6 +430,11 @@ def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None
"""
suite = self._remove_current_item().update(attributes)
logger.debug(f"ReportPortal - End Suite: {suite.robot_attributes}")
if attributes["status"] == "FAIL" and self._remove_data_passed_tests:
self._post_skipped_keywords(suite)
elif self._remove_data_passed_tests:
for kwd in suite.skipped_keywords:
self._log_keyword_content_removed(kwd.rp_item_id, kwd.start_time)
self.service.finish_suite(suite=suite, ts=ts)
if attributes["id"] == MAIN_SUITE_ID:
self.finish_launch(attributes, ts)
Expand All @@ -441,16 +456,6 @@ def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> N
test.rp_item_id = self.service.start_test(test=test, ts=ts)
self._add_current_item(test)

def _log_data_removed(self, item_id: str, timestamp: str, message: str) -> None:
msg = LogMessage(message)
msg.level = "DEBUG"
msg.item_id = item_id
msg.timestamp = timestamp
self.__post_log_message(msg)

def _log_keyword_content_removed(self, item_id: str, timestamp: str) -> None:
self._log_data_removed(item_id, timestamp, REMOVED_KEYWORD_CONTENT_LOG)

@check_rp_enabled
def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
"""Finish started test case at the ReportPortal.
Expand Down
10 changes: 4 additions & 6 deletions robotframework_reportportal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Entity:
remove_origin: Optional[Any]
rp_item_id: Optional[str]
parent: Optional["Entity"]
skipped_keywords: List["Keyword"]
posted: bool

def __init__(self, entity_type: str, parent: Optional["Entity"]):
"""Initialize required attributes.
Expand All @@ -50,6 +52,8 @@ def __init__(self, entity_type: str, parent: Optional["Entity"]):
self.flattened = False
self.remove_filter = None
self.remove_origin = None
self.skipped_keywords = []
self.posted = True

@property
def rp_parent_item_id(self):
Expand Down Expand Up @@ -94,8 +98,6 @@ class Keyword(Entity):
tags: List[str]
type: str = "KEYWORD"
skipped_logs: List[LogMessage]
skipped_keywords: List["Keyword"]
posted: bool

def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Entity):
"""Initialize required attributes.
Expand All @@ -118,9 +120,7 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Entity):
self.status = robot_attributes.get("status")
self.tags = robot_attributes["tags"]
self.type = "KEYWORD"
self.skipped_keywords = []
self.skipped_logs = []
self.posted = True

def get_name(self) -> str:
"""Get name of the keyword suitable for ReportPortal."""
Expand Down Expand Up @@ -257,7 +257,6 @@ class Test(Entity):
start_time: str
status: str
template: str
skipped_keywords: List[Keyword]

def __init__(self, name: str, robot_attributes: Dict[str, Any], test_attributes: List[str], parent: Entity):
"""Initialize required attributes.
Expand All @@ -281,7 +280,6 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], test_attributes:
self.start_time = robot_attributes["starttime"]
self.status = robot_attributes.get("status")
self.template = robot_attributes["template"]
self.skipped_keywords = []

@property
def critical(self) -> bool:
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/test_remove_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,33 @@ def test_remove_keyword_not_provided(mock_client_init):
2,
"To less executions error",
),
(
"examples/before_after/before_suite_with_steps.robot",
"PASSED",
0,
["PASSED"] * 4,
2,
0,
"Content removed using the --remove-keywords option.",
),
(
"examples/before_after/after_suite_with_steps.robot",
"PASSED",
0,
["PASSED"] * 4,
2,
1,
"Content removed using the --remove-keywords option.",
),
(
"examples/before_after/before_suite_with_steps_fail.robot",
"PASSED",
1,
["FAILED"] * 4,
1,
0,
"Suite setup step",
),
],
)
@mock.patch(REPORT_PORTAL_SERVICE)
Expand Down

0 comments on commit 9e50c17

Please sign in to comment.