Skip to content

Commit

Permalink
Remove keywords: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 16, 2024
1 parent 10f9557 commit b07a353
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 23 additions & 7 deletions robotframework_reportportal/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions robotframework_reportportal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit b07a353

Please sign in to comment.