Skip to content

Commit d9fc77c

Browse files
author
Ivan Ivanou
committed
Add support for launch and test attributes.
1 parent 6399511 commit d9fc77c

File tree

5 files changed

+60
-16
lines changed

5 files changed

+60
-16
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ NOT REQUIRED:
5555
- ID of existing Report Portal launch
5656
--variable RP_LAUNCH_DOC:"some_documentation_for_launch"
5757
- Description for the launch
58-
--variable RP_LAUNCH_TAGS:"RF Smoke"
59-
- Space-separated list of tags for the launch
58+
--variable RP_LAUNCH_ATTRIBUTES:"RF tag_name:tag_value"
59+
- Space-separated list of tags/attributes for the launch
60+
--variable RP_TEST_ATTRIBUTES:"Long"
61+
- Space-separated list of tags/attributes for the tests
6062
--variable RP_LOG_BATCH_SIZE:"10"
6163
- Default value is "20", affects size of async batch log requests
6264
```

robotframework_reportportal/listener.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
22

3+
from reportportal_client.helpers import gen_attributes
4+
35
from .variables import Variables
46
from .model import Keyword, Test, Suite, LogMessage
57
from .service import RobotService
@@ -15,8 +17,10 @@ def start_launch(launch):
1517
launch.doc = Variables.launch_doc
1618
logging.debug("ReportPortal - Start Launch: {0}".format(
1719
launch.attributes))
18-
RobotService.start_launch(launch_name=Variables.launch_name,
19-
launch=launch)
20+
RobotService.start_launch(
21+
launch_name=Variables.launch_name,
22+
attributes=gen_attributes(Variables.launch_attributes),
23+
description=launch.doc)
2024
else:
2125
RobotService.rp.launch_id = Variables.launch_id
2226

@@ -35,8 +39,10 @@ def start_suite(name, attributes):
3539
else:
3640
logging.debug("ReportPortal - Start Suite: {0}".format(attributes))
3741
parent_id = items[-1][0] if items else None
38-
item_id = RobotService.start_suite(name=name, suite=suite,
39-
parent_item_id=parent_id)
42+
item_id = RobotService.start_suite(
43+
name=name,
44+
suite=suite,
45+
parent_item_id=parent_id)
4046
items.append((item_id, parent_id))
4147

4248

@@ -56,7 +62,11 @@ def start_test(name, attributes):
5662
logging.debug("ReportPortal - Start Test: {0}".format(attributes))
5763
parent_item_id = items[-1][0]
5864
items.append((
59-
RobotService.start_test(test=test, parent_item_id=parent_item_id),
65+
RobotService.start_test(
66+
test=test,
67+
parent_item_id=parent_item_id,
68+
attributes=gen_attributes(Variables.test_attributes + test.tags),
69+
),
6070
parent_item_id))
6171

6272

robotframework_reportportal/service.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import logging
22
import traceback
33
from time import time
4-
from reportportal_client import ReportPortalService
4+
from reportportal_client.service import (
5+
_dict_to_payload,
6+
ReportPortalService
7+
)
8+
9+
from .variables import Variables
510

611

712
def async_error_handler(exc_info):
@@ -32,6 +37,19 @@ class RobotService(object):
3237
"ERROR": "ERROR"
3338
}
3439

40+
@staticmethod
41+
def _get_launch_attributes(cmd_attrs):
42+
"""Generate launch attributes including both system and user ones.
43+
44+
:param list cmd_attrs: List for attributes from the pytest.ini file
45+
"""
46+
attributes = cmd_attrs or []
47+
system_info = RobotService.rp.get_system_information(
48+
Variables.agent_name)
49+
system_info['system'] = True
50+
system_attributes = _dict_to_payload(system_info)
51+
return attributes + system_attributes
52+
3553
@staticmethod
3654
def init_service(endpoint, project, uuid):
3755
if RobotService.rp is None:
@@ -52,11 +70,20 @@ def terminate_service():
5270
RobotService.rp.terminate()
5371

5472
@staticmethod
55-
def start_launch(launch_name, mode=None, launch=None):
73+
def start_launch(launch_name, attributes=None, description=None, mode=None):
74+
"""Call start_launch method of the common client.
75+
76+
:param launch_name: Launch name
77+
:param attributes: Launch attributes
78+
:param description: Launch description
79+
:param mode: Launch mode
80+
:return: launch UUID
81+
"""
5682
sl_pt = {
83+
"attributes": RobotService._get_launch_attributes(attributes),
5784
"name": launch_name,
5885
"start_time": timestamp(),
59-
"description": launch.doc,
86+
"description": description,
6087
"mode": mode
6188
}
6289
logging.debug("ReportPortal - Start launch: "
@@ -74,9 +101,10 @@ def finish_launch(launch=None):
74101
RobotService.rp.finish_launch(**fl_rq)
75102

76103
@staticmethod
77-
def start_suite(name=None, suite=None, parent_item_id=None):
104+
def start_suite(name=None, suite=None, parent_item_id=None, attributes=None):
78105
start_rq = {
79106
"name": name,
107+
"attributes": attributes,
80108
"description": suite.doc,
81109
"start_time": timestamp(),
82110
"item_type": "SUITE",
@@ -101,11 +129,12 @@ def finish_suite(item_id, issue=None, suite=None):
101129
RobotService.rp.finish_test_item(**fta_rq)
102130

103131
@staticmethod
104-
def start_test(test=None, parent_item_id=None):
132+
def start_test(test=None, parent_item_id=None, attributes=None):
105133
# Item type should be sent as "STEP" until we upgrade to RPv6.
106134
# Details at: https://github.com/reportportal/agent-Python-RobotFramework/issues/56
107135
start_rq = {
108136
"name": test.name,
137+
"attributes": attributes,
109138
"description": test.doc,
110139
"start_time": timestamp(),
111140
"item_type": "STEP",

robotframework_reportportal/variables.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ def get_variable(name, default=None):
88

99

1010
class Variables(object):
11+
agent_name = 'robotframework-reportportal'
1112
uuid = None
1213
endpoint = None
1314
launch_name = None
1415
project = None
1516
launch_doc = None
1617
log_batch_size = None
17-
launch_tags = None
18+
launch_attributes = None
1819
launch_id = None
20+
test_attributes = None
1921

2022
@staticmethod
2123
def check_variables():
@@ -39,7 +41,8 @@ def check_variables():
3941
raise RobotServiceException(
4042
"Missing parameter RP_PROJECT for robot run\n"
4143
"You should pass -v RP_PROJECT:<project_name_value>")
44+
Variables.launch_attributes = get_variable("RP_LAUNCH_ATTRIBUTES", default="").split()
4245
Variables.launch_id = get_variable("RP_LAUNCH_UUID", default=None)
4346
Variables.launch_doc = get_variable("RP_LAUNCH_DOC", default=None)
44-
Variables.launch_tags = get_variable("RP_LAUNCH_TAGS", default="").split(" ")
4547
Variables.log_batch_size = int(get_variable("RP_LOG_BATCH_SIZE", default="20"))
48+
Variables.test_attributes = get_variable("RP_TEST_ATTRIBUTES", default="").split()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from setuptools import setup, find_packages
22

33

4-
__version__ = '5.0.2'
4+
__version__ = '5.0.3'
55

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

0 commit comments

Comments
 (0)