From b07a35328ab3baf052ec5f77624ed845d2233955 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 16 Dec 2024 15:52:59 +0300 Subject: [PATCH] Remove keywords: WIP --- robotframework_reportportal/listener.py | 30 +++++++++++++++++++------ robotframework_reportportal/model.py | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/robotframework_reportportal/listener.py b/robotframework_reportportal/listener.py index 83a7085..82d501a 100644 --- a/robotframework_reportportal/listener.py +++ b/robotframework_reportportal/listener.py @@ -42,6 +42,8 @@ TRUNCATION_SIGN = "...'" REMOVED_KEYWORD_LOG = 'Keyword data removed using --RemoveKeywords option.' WKUS_KEYWORD_NAME = 'BuiltIn.Wait Until Keyword Succeeds' +FOR_KEYWORD_NAME = 'BuiltIn.For' +WHILE_KEYWORD_NAME = 'BuiltIn.While' def check_rp_enabled(func): @@ -94,6 +96,8 @@ def match(self, kw: Keyword) -> bool: WKUS_KEYWORD_MATCH = _KeywordNameMatch(WKUS_KEYWORD_NAME) +FOR_KEYWORD_MATCH = _KeywordNameMatch(FOR_KEYWORD_NAME) +WHILE_KEYWORD_NAME = _KeywordNameMatch(WHILE_KEYWORD_NAME) # noinspection PyPep8Naming @@ -214,7 +218,7 @@ def _log_message(self, message: LogMessage) -> None: current_item = self.current_item if current_item and not getattr(current_item, 'posted', True) and message.level not in ['ERROR', 'WARN']: self.current_item.skipped_logs.append(message) - else: + elif getattr(current_item, 'matched_filter', None) is not WKUS_KEYWORD_MATCH: # Post everything skipped by '--removekeywords' option self._post_skipped_keywords() self.service.log(message=message) @@ -280,13 +284,15 @@ def _process_keyword_skip(self): self._remove_keywords = True break if pattern_str_upper in {'NOT_RUN', 'NOTRUN', 'NOT RUN'}: - self._keyword_filters = [_KeywordStatusMatch('NOT RUN')] + self._keyword_filters.append(_KeywordStatusMatch('NOT RUN')) continue if pattern_str_upper in {'FOR', 'WHILE', 'WUKS'}: if pattern_str_upper == 'WUKS': - self._keyword_filters = [WKUS_KEYWORD_MATCH] + self._keyword_filters.append(WKUS_KEYWORD_MATCH) + elif pattern_str_upper == 'FOR': + self._keyword_filters.append(FOR_KEYWORD_MATCH) else: - self._keyword_filters = [_KeywordNameMatch(pattern_str)] + self._keyword_filters.append(WHILE_KEYWORD_NAME) continue if ':' in pattern_str: pattern_type, pattern = pattern_str.split(':', 1) @@ -430,7 +436,16 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) - parent = self.current_item kwd.rp_parent_item_id = parent.rp_item_id skip_kwd = parent.remove_data - kwd.remove_data = skip_kwd or self._remove_keyword_data or any(m.match(kwd) for m in self._keyword_filters) + kwd.remove_data = skip_kwd or self._remove_keyword_data + + if kwd.remove_data: + kwd.matched_filter = getattr(parent, 'matched_filter', None) + else: + for m in self._keyword_filters: + if m.match(kwd): + kwd.remove_data = True + kwd.matched_filter = m + break if skip_kwd: kwd.rp_item_id = str(uuid.uuid4()) @@ -455,10 +470,11 @@ def end_keyword(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = No :param attributes: Dictionary passed by the Robot Framework :param ts: Timestamp(used by the ResultVisitor) """ - if attributes.get('status') == 'FAIL' and not self.current_item.posted: + kwd = self.current_item.update(attributes) + if kwd.status == 'FAIL' and not kwd.posted and kwd.matched_filter is not WKUS_KEYWORD_MATCH: self._post_skipped_keywords() - kwd = self._remove_current_item().update(attributes) + self._remove_current_item() if not kwd.posted: return self._do_end_keyword(kwd, ts) diff --git a/robotframework_reportportal/model.py b/robotframework_reportportal/model.py index 97f0d8a..b5b2d43 100644 --- a/robotframework_reportportal/model.py +++ b/robotframework_reportportal/model.py @@ -64,6 +64,7 @@ class Keyword: skipped_keywords: List['Keyword'] posted: bool remove_data: bool + matched_filter: Any def __init__(self, name: str, robot_attributes: Dict[str, Any], parent_type: Optional[str] = None): """Initialize required attributes. @@ -92,6 +93,7 @@ def __init__(self, name: str, robot_attributes: Dict[str, Any], parent_type: Opt self.skipped_logs = [] self.posted = True self.remove_data = False + self.matched_filter = None def get_name(self) -> str: """Get name of the keyword suitable for ReportPortal."""