Skip to content

Commit 8ec78d7

Browse files
committed
Revert "Revert "Fixed SETUP / TEARDOWN keyword removing""
This reverts commit d4a5c57.
1 parent d4a5c57 commit 8ec78d7

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Fixed
5+
- SETUP / TEARDOWN keyword removing, by @HardNorth
46

57
## [5.6.1]
68
### Added
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*** Settings ***
2+
Suite Setup Log suite setup
3+
4+
*** Test Cases ***
5+
My first test
6+
Log My first test
7+
8+
*** Keywords ***
9+
Log suite setup
10+
Fail Suite setup step

robotframework_reportportal/listener.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) ->
410410
suite.rp_item_id = self.service.start_suite(suite=suite, ts=ts)
411411
self._add_current_item(suite)
412412

413+
def _log_data_removed(self, item_id: str, timestamp: str, message: str) -> None:
414+
msg = LogMessage(message)
415+
msg.level = "DEBUG"
416+
msg.item_id = item_id
417+
msg.timestamp = timestamp
418+
self.__post_log_message(msg)
419+
420+
def _log_keyword_content_removed(self, item_id: str, timestamp: str) -> None:
421+
self._log_data_removed(item_id, timestamp, REMOVED_KEYWORD_CONTENT_LOG)
422+
413423
@check_rp_enabled
414424
def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
415425
"""Finish started test suite at the ReportPortal.
@@ -420,6 +430,11 @@ def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None
420430
"""
421431
suite = self._remove_current_item().update(attributes)
422432
logger.debug(f"ReportPortal - End Suite: {suite.robot_attributes}")
433+
if attributes["status"] == "FAIL" and self._remove_data_passed_tests:
434+
self._post_skipped_keywords(suite)
435+
elif self._remove_data_passed_tests:
436+
for kwd in suite.skipped_keywords:
437+
self._log_keyword_content_removed(kwd.rp_item_id, kwd.start_time)
423438
self.service.finish_suite(suite=suite, ts=ts)
424439
if attributes["id"] == MAIN_SUITE_ID:
425440
self.finish_launch(attributes, ts)
@@ -441,16 +456,6 @@ def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> N
441456
test.rp_item_id = self.service.start_test(test=test, ts=ts)
442457
self._add_current_item(test)
443458

444-
def _log_data_removed(self, item_id: str, timestamp: str, message: str) -> None:
445-
msg = LogMessage(message)
446-
msg.level = "DEBUG"
447-
msg.item_id = item_id
448-
msg.timestamp = timestamp
449-
self.__post_log_message(msg)
450-
451-
def _log_keyword_content_removed(self, item_id: str, timestamp: str) -> None:
452-
self._log_data_removed(item_id, timestamp, REMOVED_KEYWORD_CONTENT_LOG)
453-
454459
@check_rp_enabled
455460
def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
456461
"""Finish started test case at the ReportPortal.

robotframework_reportportal/model.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Entity:
3636
remove_origin: Optional[Any]
3737
rp_item_id: Optional[str]
3838
parent: Optional["Entity"]
39+
skipped_keywords: List["Keyword"]
40+
posted: bool
3941

4042
def __init__(self, entity_type: str, parent: Optional["Entity"]):
4143
"""Initialize required attributes.
@@ -50,6 +52,8 @@ def __init__(self, entity_type: str, parent: Optional["Entity"]):
5052
self.flattened = False
5153
self.remove_filter = None
5254
self.remove_origin = None
55+
self.skipped_keywords = []
56+
self.posted = True
5357

5458
@property
5559
def rp_parent_item_id(self):
@@ -94,8 +98,6 @@ class Keyword(Entity):
9498
tags: List[str]
9599
type: str = "KEYWORD"
96100
skipped_logs: List[LogMessage]
97-
skipped_keywords: List["Keyword"]
98-
posted: bool
99101

100102
def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Entity):
101103
"""Initialize required attributes.
@@ -118,9 +120,7 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], parent: Entity):
118120
self.status = robot_attributes.get("status")
119121
self.tags = robot_attributes["tags"]
120122
self.type = "KEYWORD"
121-
self.skipped_keywords = []
122123
self.skipped_logs = []
123-
self.posted = True
124124

125125
def get_name(self) -> str:
126126
"""Get name of the keyword suitable for ReportPortal."""
@@ -257,7 +257,6 @@ class Test(Entity):
257257
start_time: str
258258
status: str
259259
template: str
260-
skipped_keywords: List[Keyword]
261260

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

286284
@property
287285
def critical(self) -> bool:

tests/integration/test_remove_keywords.py

+27
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,33 @@ def test_remove_keyword_not_provided(mock_client_init):
302302
2,
303303
"To less executions error",
304304
),
305+
(
306+
"examples/before_after/before_suite_with_steps.robot",
307+
"PASSED",
308+
0,
309+
["PASSED"] * 4,
310+
2,
311+
0,
312+
"Content removed using the --remove-keywords option.",
313+
),
314+
(
315+
"examples/before_after/after_suite_with_steps.robot",
316+
"PASSED",
317+
0,
318+
["PASSED"] * 4,
319+
2,
320+
1,
321+
"Content removed using the --remove-keywords option.",
322+
),
323+
(
324+
"examples/before_after/before_suite_with_steps_fail.robot",
325+
"PASSED",
326+
1,
327+
["FAILED"] * 4,
328+
1,
329+
0,
330+
"Suite setup step",
331+
),
305332
],
306333
)
307334
@mock.patch(REPORT_PORTAL_SERVICE)

0 commit comments

Comments
 (0)