Skip to content

Commit

Permalink
Fix for offline reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
iivanou authored May 19, 2021
1 parent 11618ba commit 504a193
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
7 changes: 6 additions & 1 deletion robotframework_reportportal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def __init__(self, name, attributes):
:param name: Name of the test
:param attributes: Test attributes passed through the listener
"""
self._critical = attributes.get('critical', 'yes')
self._tags = attributes['tags']
self.attributes = attributes
self.code_ref = '{0}:{1}'.format(attributes['source'], name)
# for backward compatibility with Robot < 4.0 mark every test case
# as critical if not set
self.critical = attributes.get('critical', 'yes') == 'yes'
self.doc = attributes['doc']
self.end_time = attributes.get('endtime', '')
self.longname = attributes['longname']
Expand All @@ -97,6 +97,11 @@ def __init__(self, name, attributes):
self.template = attributes['template']
self.type = 'TEST'

@property
def critical(self):
"""Form unique value for RF 4.0+ and older versions."""
return self._critical in ('yes', True)

@property
def tags(self):
"""Get list of test tags excluding test_case_id."""
Expand Down
4 changes: 3 additions & 1 deletion robotframework_reportportal/model.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Launch(Suite):
def __init__(self, name: Text, attributes: Dict[Text, Any]) -> None: ...

class Test:
_critical: Text = ...
_tags: List[Text] = ...
attributes: Dict[Text, Any] = ...
code_ref: Text = ...
critical: Text = ...
doc: Text = ...
end_time: Text = ...
longname: Text = ...
Expand All @@ -46,6 +46,8 @@ class Test:
type: Text = 'TEST'
def __init__(self, name: Text, attributes: Dict[Text, Any]) -> None: ...
@property
def critical(self) -> bool: ...
@property
def tags(self) -> List[Text]: ...
@property
def test_case_id(self) -> Optional[Text]: ...
Expand Down
2 changes: 2 additions & 0 deletions robotframework_reportportal/result_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def start_test(self, test):
# for backward compatibility with Robot < 4.0 mark every test case
# as critical if not set
'critical': getattr(test, 'critical', 'yes'),
'source': test.source,
'template': '',
# 'lineno': test.lineno,
'starttime': ts,
Expand All @@ -95,6 +96,7 @@ def end_test(self, test):
# 'lineno': test.lineno,
'endtime': ts,
'elapsedtime': test.elapsedtime,
'source': test.source,
'status': test.status,
'message': test.message,
}
Expand Down
2 changes: 1 addition & 1 deletion robotframework_reportportal/time_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _correct_ends(o, node_class):
logging.debug(
"Correcting parents' endtime to {0} based on {2}={1}"
.format(o.endtime, o.id, node_class))
if o.id == _stack[-1]:
if _stack and o.id == _stack[-1]:
_stack.pop()

def start_suite(self, suite):
Expand Down
11 changes: 7 additions & 4 deletions tests/test_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ def test_dynamic_attributes(self, mock_client_init, mock_listener,
{'key': 'SLID', 'value': '12345'}]

@mock.patch(REPORT_PORTAL_SERVICE)
def test_non_critical_test_skip(self, mock_client_init, mock_listener,
test_attributes):
test_attributes['critical'] = 'no'
@pytest.mark.parametrize('critical, expected_status', [
(True, 'FAILED'), ('yes', 'FAILED'), ('no', 'SKIPPED')])
def test_non_critical_test_skip(
self, mock_client_init, mock_listener,
test_attributes, critical, expected_status):
test_attributes['critical'] = critical
mock_listener.start_test('Test', test_attributes)
test_attributes['status'] = 'FAIL'
mock_listener.end_test('Test', test_attributes)
mock_client = mock_client_init.return_value
assert mock_client.finish_test_item.call_count == 1
args, kwargs = mock_client.finish_test_item.call_args
assert kwargs['status'] == 'SKIPPED'
assert kwargs['status'] == expected_status

@mock.patch(REPORT_PORTAL_SERVICE)
@pytest.mark.parametrize('skipped_issue_value', [True, False])
Expand Down

0 comments on commit 504a193

Please sign in to comment.