Skip to content

Commit e40ab8a

Browse files
committed
Fix remove keywords for PASSED case. Add more tests
1 parent 87d2760 commit e40ab8a

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

robotframework_reportportal/listener.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class listener:
130130
_service: Optional[RobotService]
131131
_variables: Optional[Variables]
132132
_keyword_filters: List[_KeywordMatch] = []
133-
_remove_keyword_content: bool = False
134-
_remove_keywords: bool = False
133+
_remove_all_keyword_content: bool = False
134+
_remove_passed_keywords: bool = False
135135
ROBOT_LISTENER_API_VERSION = 2
136136

137137
def __init__(self) -> None:
@@ -254,7 +254,7 @@ def _log_message(self, message: LogMessage) -> None:
254254
self.current_item.skipped_logs.append(message)
255255
elif (
256256
getattr(current_item, "matched_filter", None) is not WKUS_KEYWORD_MATCH
257-
and not self._remove_keyword_content
257+
and not self._remove_all_keyword_content
258258
):
259259
# Post everything skipped by '--removekeywords' option
260260
self._post_skipped_keywords(current_item)
@@ -318,10 +318,10 @@ def _process_keyword_skip(self):
318318
for pattern_str in set(current_context.output._settings.remove_keywords):
319319
pattern_str_upper = pattern_str.upper()
320320
if "ALL" == pattern_str_upper:
321-
self._remove_keyword_content = True
321+
self._remove_all_keyword_content = True
322322
break
323323
if "PASSED" == pattern_str_upper:
324-
self._remove_keywords = True
324+
self._remove_passed_keywords = True
325325
break
326326
if pattern_str_upper in {"NOT_RUN", "NOTRUN", "NOT RUN"}:
327327
self._keyword_filters.append(_KeywordStatusEqual("NOT RUN"))
@@ -391,12 +391,9 @@ def start_suite(self, name: str, attributes: Dict, ts: Optional[Any] = None) ->
391391
else:
392392
logger.debug(f"ReportPortal - Start Suite: {attributes}")
393393
suite = Suite(name, attributes)
394-
suite.remove_data = self._remove_keywords
395394
suite.rp_parent_item_id = self.parent_id
396395
suite.rp_item_id = self.service.start_suite(suite=suite, ts=ts)
397396
self._add_current_item(suite)
398-
if suite.remove_data:
399-
self._log_keyword_data_removed(suite.rp_item_id, suite.start_time)
400397

401398
@check_rp_enabled
402399
def end_suite(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
@@ -437,13 +434,10 @@ def start_test(self, name: str, attributes: Dict, ts: Optional[Any] = None) -> N
437434
attributes = attributes.copy()
438435
attributes["source"] = getattr(self.current_item, "source", None)
439436
test = Test(name=name, robot_attributes=attributes, test_attributes=self.variables.test_attributes)
440-
test.remove_data = self._remove_keywords
441437
logger.debug(f"ReportPortal - Start Test: {attributes}")
442438
test.rp_parent_item_id = self.parent_id
443439
test.rp_item_id = self.service.start_test(test=test, ts=ts)
444440
self._add_current_item(test)
445-
if test.remove_data:
446-
self._log_keyword_data_removed(test.rp_item_id, test.start_time)
447441

448442
@check_rp_enabled
449443
def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None) -> None:
@@ -482,7 +476,8 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -
482476
parent = self.current_item
483477
kwd.rp_parent_item_id = parent.rp_item_id
484478
skip_kwd = parent.remove_data
485-
kwd.remove_data = skip_kwd or self._remove_keyword_content
479+
skip_data = self._remove_all_keyword_content or self._remove_passed_keywords
480+
kwd.remove_data = skip_kwd or skip_data
486481

487482
if kwd.remove_data:
488483
kwd.matched_filter = getattr(parent, "matched_filter", None)
@@ -501,7 +496,7 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -
501496
kwd.posted = False
502497
else:
503498
self._do_start_keyword(kwd, ts)
504-
if self._remove_keyword_content:
499+
if skip_data:
505500
self._log_keyword_content_removed(kwd.rp_item_id, kwd.start_time)
506501

507502
self._add_current_item(kwd)

robotframework_reportportal/model.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ class Suite:
150150
tests: List[str]
151151
total_tests: int
152152
type: str = "SUITE"
153-
skipped_keywords: List[Keyword]
154-
remove_data: bool
153+
remove_data: bool = False
155154

156155
def __init__(self, name: str, robot_attributes: Dict[str, Any]):
157156
"""Initialize required attributes.
@@ -176,8 +175,6 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any]):
176175
self.tests = robot_attributes["tests"]
177176
self.total_tests = robot_attributes["totaltests"]
178177
self.type = "SUITE"
179-
self.skipped_keywords = []
180-
self.remove_data = False
181178

182179
@property
183180
def attributes(self) -> Optional[List[Dict[str, str]]]:
@@ -246,8 +243,7 @@ class Test:
246243
status: str
247244
template: str
248245
type: str = "TEST"
249-
skipped_keywords: List[Keyword]
250-
remove_data: bool
246+
remove_data: bool = False
251247

252248
def __init__(self, name: str, robot_attributes: Dict[str, Any], test_attributes: List[str]):
253249
"""Initialize required attributes.
@@ -273,8 +269,6 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], test_attributes:
273269
self.status = robot_attributes.get("status")
274270
self.template = robot_attributes["template"]
275271
self.type = "TEST"
276-
self.skipped_keywords = []
277-
self.remove_data = False
278272

279273
@property
280274
def critical(self) -> bool:

tests/integration/test_remove_keywords.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@
131131
1,
132132
"Content removed using the --remove-keywords option.",
133133
),
134+
(
135+
"examples/rkie_keyword.robot",
136+
"PASSED",
137+
0,
138+
["PASSED"] * 4,
139+
2,
140+
0,
141+
"Content removed using the --remove-keywords option.",
142+
),
134143
],
135144
)
136145
@mock.patch(REPORT_PORTAL_SERVICE)

0 commit comments

Comments
 (0)