Skip to content

Commit ad26935

Browse files
author
Ivan Ivanou
committed
WIP: Support for V5 changes in client.
1 parent 173ce99 commit ad26935

File tree

4 files changed

+63
-69
lines changed

4 files changed

+63
-69
lines changed

robotframework_reportportal/listener.py

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,75 @@
77
ROBOT_LISTENER_API_VERSION = 2
88

99

10-
class ParentTypes(object):
11-
12-
items = []
13-
14-
@staticmethod
15-
def push(item):
16-
ParentTypes.items.append(item)
17-
18-
@staticmethod
19-
def pop():
20-
return ParentTypes.items.pop()
21-
22-
@staticmethod
23-
def peek():
24-
return ParentTypes.items[-1]
25-
26-
@staticmethod
27-
def is_empty():
28-
return ParentTypes.items == []
10+
items = []
2911

3012

3113
def start_suite(name, attributes):
3214
suite = Suite(attributes=attributes)
33-
ParentTypes.push("SUITE")
34-
if attributes["id"] == "s1":
15+
if suite.robot_id == "s1":
3516
Variables.check_variables()
3617
RobotService.init_service(Variables.endpoint, Variables.project,
37-
Variables.uuid, Variables.log_batch_size)
18+
Variables.uuid)
3819
suite.doc = Variables.launch_doc
3920
logging.debug("ReportPortal - Start Launch: {0}".format(attributes))
4021
RobotService.start_launch(launch_name=Variables.launch_name,
4122
launch=suite)
23+
if not suite.suites:
24+
attributes['id'] = "s1-s1"
25+
start_suite(name, attributes)
26+
4227
else:
4328
logging.debug("ReportPortal - Start Suite: {0}".format(attributes))
44-
RobotService.start_suite(name=name, suite=suite)
29+
parent_id = items[-1][0] if items else None
30+
item_id = RobotService.start_suite(name=name, suite=suite,
31+
parent_item_id=parent_id)
32+
items.append((item_id, parent_id))
4533

4634

47-
def end_suite(name, attributes):
35+
def end_suite(_, attributes):
4836
suite = Suite(attributes=attributes)
49-
ParentTypes.pop()
50-
if attributes["id"] == "s1":
37+
if suite.robot_id == "s1":
5138
logging.debug(msg="ReportPortal - End Launch: {0}".format(attributes))
5239
RobotService.finish_launch(launch=suite)
5340
RobotService.terminate_service()
5441
else:
5542
logging.debug("ReportPortal - End Suite: {0}".format(attributes))
56-
RobotService.finish_suite(suite=suite)
43+
RobotService.finish_suite(item_id=items.pop()[0], suite=suite)
5744

5845

5946
def start_test(name, attributes):
6047
test = Test(name=name, attributes=attributes)
61-
ParentTypes.push("TEST")
6248
logging.debug("ReportPortal - Start Test: {0}".format(attributes))
63-
RobotService.start_test(test=test)
49+
parent_item_id = items[-1][0]
50+
items.append((
51+
RobotService.start_test(test=test, parent_item_id=parent_item_id),
52+
parent_item_id))
6453

6554

6655
def end_test(name, attributes):
6756
test = Test(name=name, attributes=attributes)
68-
ParentTypes.pop()
57+
item_id, _ = items.pop()
6958
logging.debug("ReportPortal - End Test: {0}".format(attributes))
70-
RobotService.finish_test(test=test)
59+
RobotService.finish_test(item_id=item_id, test=test)
7160

7261

7362
def start_keyword(name, attributes):
74-
parent_type = "SUITE" if ParentTypes.is_empty() else ParentTypes.peek()
63+
parent_type = 'SUITE' if not items else 'TEST'
64+
parent_item_id = items[-1][0]
7565
kwd = Keyword(name=name, parent_type=parent_type, attributes=attributes)
66+
has_stats = False if kwd.get_type() == "STEP" else True
7667
logging.debug("ReportPortal - Start Keyword: {0}".format(attributes))
77-
RobotService.start_keyword(keyword=kwd)
68+
items.append((
69+
RobotService.start_keyword(keyword=kwd, parent_item_id=parent_item_id,
70+
has_stats=has_stats),
71+
parent_item_id))
7872

7973

8074
def end_keyword(name, attributes):
8175
kwd = Keyword(name=name, attributes=attributes)
76+
item_id, _ = items.pop()
8277
logging.debug("ReportPortal - End Keyword: {0}".format(attributes))
83-
RobotService.finish_keyword(keyword=kwd)
78+
RobotService.finish_keyword(item_id=item_id, keyword=kwd)
8479

8580

8681
def log_message(message):
@@ -127,5 +122,5 @@ def xunit_file(path):
127122
logging.debug("ReportPortal - XUnit File: {0}".format(path))
128123

129124

130-
def debug_file(path):
131-
logging.debug("ReportPortal - Debug File: {0}".format(path))
125+
def info_file(path):
126+
logging.debug("ReportPortal - info File: {0}".format(path))

robotframework_reportportal/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, name=None, attributes=None):
4242

4343

4444
class Keyword(object):
45-
def __init__(self, name=None, parent_type="SUITE", attributes=None):
45+
def __init__(self, name=None, parent_type="TEST", attributes=None):
4646
super(Keyword, self).__init__()
4747
self.name = name
4848
self.libname = attributes["libname"]

robotframework_reportportal/service.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import logging
22
import traceback
33
from time import time
4-
from reportportal_client import ReportPortalServiceAsync
5-
from .variables import Variables
4+
from reportportal_client import ReportPortalService
65

76

87
def async_error_handler(exc_info):
@@ -34,18 +33,16 @@ class RobotService(object):
3433
}
3534

3635
@staticmethod
37-
def init_service(endpoint, project, uuid, log_batch_size):
36+
def init_service(endpoint, project, uuid):
3837
if RobotService.rp is None:
3938
logging.debug(
4039
"ReportPortal - Init service: "
4140
"endpoint={0}, project={1}, uuid={2}"
4241
.format(endpoint, project, uuid))
43-
RobotService.rp = ReportPortalServiceAsync(
42+
RobotService.rp = ReportPortalService(
4443
endpoint=endpoint,
4544
project=project,
46-
token=uuid,
47-
error_handler=async_error_handler,
48-
log_batch_size=log_batch_size)
45+
token=uuid)
4946
else:
5047
raise Exception("RobotFrameworkService is already initialized")
5148

@@ -60,12 +57,11 @@ def start_launch(launch_name, mode=None, launch=None):
6057
"name": launch_name,
6158
"start_time": timestamp(),
6259
"description": launch.doc,
63-
"mode": mode,
64-
"tags": Variables.launch_tags
60+
"mode": mode
6561
}
6662
logging.debug("ReportPortal - Start launch: "
6763
"request_body={0}".format(sl_pt))
68-
RobotService.rp.start_launch(**sl_pt)
64+
return RobotService.rp.start_launch(**sl_pt)
6965

7066
@staticmethod
7167
def finish_launch(launch=None):
@@ -78,77 +74,81 @@ def finish_launch(launch=None):
7874
RobotService.rp.finish_launch(**fl_rq)
7975

8076
@staticmethod
81-
def start_suite(name=None, suite=None):
77+
def start_suite(name=None, suite=None, parent_item_id=None):
8278
start_rq = {
8379
"name": name,
8480
"description": suite.doc,
85-
"tags": [],
8681
"start_time": timestamp(),
87-
"item_type": "SUITE"
82+
"item_type": "SUITE",
83+
"parent_item_id": parent_item_id
8884
}
8985
logging.debug(
9086
"ReportPortal - Start suite: "
9187
"request_body={0}".format(start_rq))
92-
RobotService.rp.start_test_item(**start_rq)
88+
return RobotService.rp.start_test_item(**start_rq)
9389

9490
@staticmethod
95-
def finish_suite(issue=None, suite=None):
91+
def finish_suite(item_id, issue=None, suite=None):
9692
fta_rq = {
9793
"end_time": timestamp(),
9894
"status": RobotService.status_mapping[suite.status],
99-
"issue": issue
95+
"issue": issue,
96+
"item_id": item_id
10097
}
10198
logging.debug(
10299
"ReportPortal - Finish suite:"
103100
" request_body={0}".format(fta_rq))
104101
RobotService.rp.finish_test_item(**fta_rq)
105102

106103
@staticmethod
107-
def start_test(test=None):
104+
def start_test(test=None, parent_item_id=None):
108105
start_rq = {
109106
"name": test.name,
110107
"description": test.doc,
111-
"tags": test.tags,
112108
"start_time": timestamp(),
113-
"item_type": "TEST"
109+
"item_type": "TEST",
110+
"parent_item_id": parent_item_id
114111
}
115112
logging.debug(
116113
"ReportPortal - Start test: "
117114
"request_body={0}".format(start_rq))
118-
RobotService.rp.start_test_item(**start_rq)
115+
return RobotService.rp.start_test_item(**start_rq)
119116

120117
@staticmethod
121-
def finish_test(issue=None, test=None):
118+
def finish_test(item_id, issue=None, test=None):
122119
fta_rq = {
123120
"end_time": timestamp(),
124121
"status": RobotService.status_mapping[test.status],
125-
"issue": issue
122+
"issue": issue,
123+
"item_id": item_id
126124
}
127125
logging.debug(
128126
"ReportPortal - Finish test:"
129127
" request_body={0}".format(fta_rq))
130128
RobotService.rp.finish_test_item(**fta_rq)
131129

132130
@staticmethod
133-
def start_keyword(keyword=None):
131+
def start_keyword(keyword=None, parent_item_id=None, has_stats=True):
134132
start_rq = {
135133
"name": keyword.get_name(),
136134
"description": keyword.doc,
137-
"tags": keyword.tags,
138135
"start_time": timestamp(),
139-
"item_type": keyword.get_type()
136+
"item_type": keyword.get_type(),
137+
"parent_item_id": parent_item_id,
138+
"has_stats": has_stats
140139
}
141140
logging.debug(
142141
"ReportPortal - Start keyword: "
143142
"request_body={0}".format(start_rq))
144-
RobotService.rp.start_test_item(**start_rq)
143+
return RobotService.rp.start_test_item(**start_rq)
145144

146145
@staticmethod
147-
def finish_keyword(issue=None, keyword=None):
146+
def finish_keyword(item_id, issue=None, keyword=None):
148147
fta_rq = {
149148
"end_time": timestamp(),
150149
"status": RobotService.status_mapping[keyword.status],
151-
"issue": issue
150+
"issue": issue,
151+
"item_id": item_id
152152
}
153153
logging.debug(
154154
"ReportPortal - Finish keyword:"

setup.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
from setuptools import setup, find_packages
22

33

4-
__version__ = '3.1.1'
4+
__version__ = '5.0.0'
55

66
requirements = [
7-
"reportportal-client~=3.0",
7+
"reportportal-client>=5.0.0",
88
"six",
99
]
1010

1111
setup(
1212
name='robotframework-reportportal',
1313
packages=find_packages(),
1414
version=__version__,
15-
description='Listener for RobotFramework reporting to ReportPortal',
16-
author='Artsiom Tkachou',
15+
description='Listener for RobotFramework reporting to ReportPortal v5',
1716
author_email='[email protected]',
1817
url='https://github.com/reportportal/agent-Python-RobotFramework',
1918
download_url=(

0 commit comments

Comments
 (0)