Skip to content

Commit 504a193

Browse files
authored
Fix for offline reporting
1 parent 11618ba commit 504a193

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

robotframework_reportportal/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ def __init__(self, name, attributes):
7878
:param name: Name of the test
7979
:param attributes: Test attributes passed through the listener
8080
"""
81+
self._critical = attributes.get('critical', 'yes')
8182
self._tags = attributes['tags']
8283
self.attributes = attributes
8384
self.code_ref = '{0}:{1}'.format(attributes['source'], name)
8485
# for backward compatibility with Robot < 4.0 mark every test case
8586
# as critical if not set
86-
self.critical = attributes.get('critical', 'yes') == 'yes'
8787
self.doc = attributes['doc']
8888
self.end_time = attributes.get('endtime', '')
8989
self.longname = attributes['longname']
@@ -97,6 +97,11 @@ def __init__(self, name, attributes):
9797
self.template = attributes['template']
9898
self.type = 'TEST'
9999

100+
@property
101+
def critical(self):
102+
"""Form unique value for RF 4.0+ and older versions."""
103+
return self._critical in ('yes', True)
104+
100105
@property
101106
def tags(self):
102107
"""Get list of test tags excluding test_case_id."""

robotframework_reportportal/model.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class Launch(Suite):
2828
def __init__(self, name: Text, attributes: Dict[Text, Any]) -> None: ...
2929

3030
class Test:
31+
_critical: Text = ...
3132
_tags: List[Text] = ...
3233
attributes: Dict[Text, Any] = ...
3334
code_ref: Text = ...
34-
critical: Text = ...
3535
doc: Text = ...
3636
end_time: Text = ...
3737
longname: Text = ...
@@ -46,6 +46,8 @@ class Test:
4646
type: Text = 'TEST'
4747
def __init__(self, name: Text, attributes: Dict[Text, Any]) -> None: ...
4848
@property
49+
def critical(self) -> bool: ...
50+
@property
4951
def tags(self) -> List[Text]: ...
5052
@property
5153
def test_case_id(self) -> Optional[Text]: ...

robotframework_reportportal/result_visitor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def start_test(self, test):
7474
# for backward compatibility with Robot < 4.0 mark every test case
7575
# as critical if not set
7676
'critical': getattr(test, 'critical', 'yes'),
77+
'source': test.source,
7778
'template': '',
7879
# 'lineno': test.lineno,
7980
'starttime': ts,
@@ -95,6 +96,7 @@ def end_test(self, test):
9596
# 'lineno': test.lineno,
9697
'endtime': ts,
9798
'elapsedtime': test.elapsedtime,
99+
'source': test.source,
98100
'status': test.status,
99101
'message': test.message,
100102
}

robotframework_reportportal/time_visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _correct_ends(o, node_class):
4646
logging.debug(
4747
"Correcting parents' endtime to {0} based on {2}={1}"
4848
.format(o.endtime, o.id, node_class))
49-
if o.id == _stack[-1]:
49+
if _stack and o.id == _stack[-1]:
5050
_stack.pop()
5151

5252
def start_suite(self, suite):

tests/test_listener.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ def test_dynamic_attributes(self, mock_client_init, mock_listener,
4848
{'key': 'SLID', 'value': '12345'}]
4949

5050
@mock.patch(REPORT_PORTAL_SERVICE)
51-
def test_non_critical_test_skip(self, mock_client_init, mock_listener,
52-
test_attributes):
53-
test_attributes['critical'] = 'no'
51+
@pytest.mark.parametrize('critical, expected_status', [
52+
(True, 'FAILED'), ('yes', 'FAILED'), ('no', 'SKIPPED')])
53+
def test_non_critical_test_skip(
54+
self, mock_client_init, mock_listener,
55+
test_attributes, critical, expected_status):
56+
test_attributes['critical'] = critical
5457
mock_listener.start_test('Test', test_attributes)
5558
test_attributes['status'] = 'FAIL'
5659
mock_listener.end_test('Test', test_attributes)
5760
mock_client = mock_client_init.return_value
5861
assert mock_client.finish_test_item.call_count == 1
5962
args, kwargs = mock_client.finish_test_item.call_args
60-
assert kwargs['status'] == 'SKIPPED'
63+
assert kwargs['status'] == expected_status
6164

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

0 commit comments

Comments
 (0)