Skip to content

Commit f632c8e

Browse files
committed
Add 'remove_keywords' configuration variable
1 parent 1ba9019 commit f632c8e

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Keywords names now contain Keyword types, by @HardNorth
88
### Added
99
- Support for `Python 3.13`, by @HardNorth
10+
- `RP_REMOVE_KEYWORDS` configuration variable, by @HardNorth
11+
- `--remove-keywords` argument support, by @HardNorth
1012
### Removed
1113
- `Python 3.7` support, by @HardNorth
1214

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ NOT REQUIRED:
9393
--variable RP_VERIFY_SSL:"True"
9494
- Default value is "True", disables SSL verification for HTTP requests.
9595
Also, you can specify a full path to your certificate as the value.
96+
--variable RP_REMOVE_KEYWORDS:"True"
97+
- Default value is "False", remove keywords from reporting, passed with '--remove-keywords' Robot's argument.
9698
```
9799

98100
### Logging

robotframework_reportportal/listener.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class listener:
131131
_variables: Optional[Variables]
132132
_keyword_filters: List[_KeywordMatch] = []
133133
_remove_all_keyword_content: bool = False
134-
_remove_passed_keywords: bool = False
134+
_remove_data_passed_tests: bool = False
135135
ROBOT_LISTENER_API_VERSION = 2
136136

137137
def __init__(self) -> None:
@@ -324,6 +324,9 @@ def variables(self) -> Variables:
324324
return self._variables
325325

326326
def _process_keyword_skip(self):
327+
if not self.variables.remove_keywords:
328+
return
329+
327330
try:
328331
self._keyword_filters = []
329332

@@ -339,7 +342,7 @@ def _process_keyword_skip(self):
339342
self._remove_all_keyword_content = True
340343
break
341344
if "PASSED" == pattern_str_upper:
342-
self._remove_passed_keywords = True
345+
self._remove_data_passed_tests = True
343346
break
344347
if pattern_str_upper in {"NOT_RUN", "NOTRUN", "NOT RUN"}:
345348
self._keyword_filters.append(_KeywordStatusEqual("NOT RUN"))
@@ -360,7 +363,7 @@ def _process_keyword_skip(self):
360363
elif "TAG" == pattern_type.upper():
361364
self._keyword_filters.append(_KeywordTagMatch(pattern.strip()))
362365
except ImportError:
363-
warn('Unable to locate Robot Framework context. "removekeywords" feature will not work.', stacklevel=2)
366+
warn('Unable to locate Robot Framework context. "--remove-keywords" feature will not work.', stacklevel=2)
364367

365368
def start_launch(self, attributes: Dict[str, Any], ts: Optional[Any] = None) -> None:
366369
"""Start a new launch at the ReportPortal.
@@ -468,9 +471,9 @@ def end_test(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = None)
468471
test = self.current_item.update(attributes)
469472
if not test.critical and test.status == "FAIL":
470473
test.status = "SKIP"
471-
if attributes["status"] == "FAIL" and self._remove_passed_keywords:
474+
if attributes["status"] == "FAIL" and self._remove_data_passed_tests:
472475
self._post_skipped_keywords(test)
473-
elif self._remove_passed_keywords:
476+
elif self._remove_data_passed_tests:
474477
for kwd in test.skipped_keywords:
475478
self._log_keyword_content_removed(kwd.rp_item_id, kwd.start_time)
476479
logger.debug(f"ReportPortal - End Test: {test.robot_attributes}")
@@ -497,7 +500,7 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -
497500
parent = self.current_item
498501
kwd.rp_parent_item_id = parent.rp_item_id
499502
skip_kwd = parent.remove_data
500-
skip_data = self._remove_all_keyword_content or self._remove_passed_keywords
503+
skip_data = self._remove_all_keyword_content or self._remove_data_passed_tests
501504
kwd.remove_data = skip_kwd or skip_data
502505

503506
if kwd.remove_data:
@@ -519,7 +522,7 @@ def start_keyword(self, name: str, attributes: Dict, ts: Optional[Any] = None) -
519522
self._do_start_keyword(kwd, ts)
520523
if skip_data:
521524
kwd.skip_origin = kwd
522-
if self._remove_passed_keywords:
525+
if self._remove_data_passed_tests:
523526
parent.skipped_keywords.append(kwd)
524527

525528
self._add_current_item(kwd)
@@ -571,7 +574,7 @@ def end_keyword(self, _: Optional[str], attributes: Dict, ts: Optional[Any] = No
571574
elif kwd.posted and kwd.remove_data and kwd.skip_origin is kwd:
572575
if self._remove_all_keyword_content:
573576
self._log_keyword_content_removed(kwd.rp_item_id, kwd.start_time)
574-
elif not self._remove_passed_keywords:
577+
elif not self._remove_data_passed_tests:
575578
self._log_keyword_data_removed(kwd.rp_item_id, kwd.start_time)
576579

577580
self._remove_current_item()

robotframework_reportportal/variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Variables:
6767
launch_uuid_print_output: Optional[OutputType]
6868
client_type: ClientType
6969
http_timeout: Optional[Union[Tuple[float, float], float]]
70+
remove_keywords: bool
7071

7172
def __init__(self) -> None:
7273
"""Initialize instance attributes."""
@@ -110,6 +111,8 @@ def __init__(self) -> None:
110111
else:
111112
self.http_timeout = connect_timeout or read_timeout
112113

114+
self.remove_keywords = to_bool(get_variable("RP_REMOVE_KEYWORDS", default="False"))
115+
113116
self.api_key = get_variable("RP_API_KEY")
114117
if not self.api_key:
115118
token = get_variable("RP_UUID")

tests/integration/test_remove_keywords.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@
1818

1919
from tests import REPORT_PORTAL_SERVICE
2020
from tests.helpers import utils
21+
from tests.helpers.utils import DEFAULT_VARIABLES
22+
23+
24+
@mock.patch(REPORT_PORTAL_SERVICE)
25+
def test_remove_keyword_not_provided(mock_client_init):
26+
mock_client = mock_client_init.return_value
27+
mock_client.start_test_item.side_effect = utils.item_id_gen
28+
29+
result = utils.run_robot_tests(
30+
["examples/for_keyword.robot"], variables=DEFAULT_VARIABLES, arguments={"--remove-keywords": "FOR"}
31+
)
32+
assert result == 0
33+
34+
launch_start = mock_client.start_launch.call_args_list
35+
launch_finish = mock_client.finish_launch.call_args_list
36+
assert len(launch_start) == len(launch_finish) == 1
37+
38+
item_start_calls = mock_client.start_test_item.call_args_list
39+
item_finish_calls = mock_client.finish_test_item.call_args_list
40+
assert len(item_start_calls) == len(item_finish_calls)
41+
assert len(item_finish_calls) == 9
42+
43+
statuses = [finish[1]["status"] for finish in item_finish_calls]
44+
assert statuses == ["PASSED"] * 9
2145

2246

2347
@pytest.mark.parametrize(
@@ -218,7 +242,9 @@ def test_for_and_while_keyword_remove(
218242
mock_client = mock_client_init.return_value
219243
mock_client.start_test_item.side_effect = utils.item_id_gen
220244

221-
result = utils.run_robot_tests([file], arguments={"--remove-keywords": keyword_to_remove})
245+
variables = DEFAULT_VARIABLES.copy()
246+
variables["RP_REMOVE_KEYWORDS"] = True
247+
result = utils.run_robot_tests([file], variables=variables, arguments={"--remove-keywords": keyword_to_remove})
222248
assert result == exit_code
223249

224250
launch_start = mock_client.start_launch.call_args_list

0 commit comments

Comments
 (0)