Skip to content

Commit 1b00478

Browse files
authored
Fix reporting of launch attributes
Fix reporting of launch attributes
2 parents 6e39be8 + 45dccab commit 1b00478

File tree

4 files changed

+49
-34
lines changed

4 files changed

+49
-34
lines changed

README.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ Example of :code:`pytest.ini`:
6969
rp_endpoint = http://192.168.1.10:8080
7070
rp_project = user_personal
7171
rp_launch = AnyLaunchName
72-
rp_launch_tags = 'PyTest' 'Smoke'
72+
rp_launch_attributes = 'PyTest' 'Smoke'
7373
rp_launch_description = 'Smoke test'
7474
rp_ignore_errors = True
75-
rp_ignore_tags = 'xfail' 'usefixture'
75+
rp_ignore_attributes = 'xfail' 'usefixture'
7676
7777
The following parameters are optional:
7878

7979
- :code:`rp_launch = AnyLaunchName` - launch name (could be overridden
8080
by pytest --rp-launch option, default value is 'Pytest Launch')
81-
- :code:`rp_launch_tags = 'PyTest' 'Smoke'` - list of tags for launch
82-
- :code:`rp_tests_tags = 'PyTest' 'Smoke'` - list of tags that will be added for each item in the launch
81+
- :code:`rp_launch_attributes = 'PyTest' 'Smoke'` - list of attributes for launch
82+
- :code:`rp_tests_attributes = 'PyTest' 'Smoke'` - list of attributes that will be added for each item in the launch
8383
- :code:`rp_launch_description = 'Smoke test'` - launch description (could be overridden
8484
by pytest --rp-launch-description option, default value is '')
8585

8686
- :code:`rp_log_batch_size = 20` - size of batch log request
8787
- :code:`rp_ignore_errors = True` - Ignore Report Portal errors (exit otherwise)
88-
- :code:`rp_ignore_tags = 'xfail' 'usefixture'` - Ignore specified pytest markers
88+
- :code:`rp_ignore_attributes = 'xfail' 'usefixture'` - Ignore specified pytest markers
8989
- :code:`rp_hierarchy_dirs = True` - Enables hierarchy for tests directories, default `False`. Doesn't support 'xdist' plugin.
9090
- :code:`rp_hierarchy_module = True` - Enables hierarchy for module, default `True`. Doesn't support 'xdist' plugin.
9191
- :code:`rp_hierarchy_class = True` - Enables hierarchy for class, default `True`. Doesn't support 'xdist' plugin.
@@ -99,7 +99,7 @@ The following parameters are optional:
9999

100100

101101
If you like to override the above parameters from command line, or from CI environment based on your build, then pass
102-
- :code:`-o "rp_launch_tags=Smoke Tests"` during invocation.
102+
- :code:`-o "rp_launch_attributes=Smoke Tests"` during invocation.
103103

104104
Examples
105105
~~~~~~~~
@@ -174,8 +174,8 @@ Plugin can report doc-strings of tests as :code:`descriptions`:
174174
"""
175175
pass
176176
177-
Pytest markers will be attached as :code:`tags` to Report Portal items.
178-
In the following example tags 'linux' and 'win32' will be used:
177+
Pytest markers will be attached as :code:`attributes` to Report Portal items.
178+
In the following example attributes 'linux' and 'win32' will be used:
179179

180180
.. code-block:: python
181181
@@ -186,7 +186,7 @@ In the following example tags 'linux' and 'win32' will be used:
186186
def test_one():
187187
pass
188188
189-
If you don't want to attach specific markers, list them in :code:`rp_ignore_tags` parameter
189+
If you don't want to attach specific markers, list them in :code:`rp_ignore_attributes` parameter
190190

191191

192192
Launching

pytest_reportportal/plugin.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ def pytest_sessionstart(session):
5555
uuid=session.config.getini('rp_uuid'),
5656
log_batch_size=int(session.config.getini('rp_log_batch_size')),
5757
ignore_errors=bool(session.config.getini('rp_ignore_errors')),
58-
ignored_tags=session.config.getini('rp_ignore_tags'),
58+
ignored_attributes=session.config.getini('rp_ignore_attributes'),
5959
verify_ssl=session.config.getini('rp_verify_ssl'),
6060
retries=int(session.config.getini('retries')),
6161
)
6262

63+
attributes = [{'value': tag} for tag in
64+
session.config.getini('rp_launch_attributes')]
6365
session.config.py_test_service.start_launch(
6466
session.config.option.rp_launch,
65-
tags=session.config.getini('rp_launch_tags'),
67+
attributes=attributes,
6668
description=session.config.option.rp_launch_description
6769
)
6870
if session.config.pluginmanager.hasplugin('xdist'):
@@ -235,14 +237,14 @@ def pytest_addoption(parser):
235237
help='Launch name')
236238

237239
parser.addini(
238-
'rp_launch_tags',
240+
'rp_launch_attributes',
239241
type='args',
240-
help='Launch tags, i.e Performance Regression')
242+
help='Launch attributes, i.e Performance Regression')
241243

242244
parser.addini(
243-
'rp_tests_tags',
245+
'rp_tests_attributes',
244246
type='args',
245-
help='Tags for all tests items, e.g. Smoke')
247+
help='Attributes for all tests items, e.g. Smoke')
246248

247249
parser.addini(
248250
'rp_launch_description',
@@ -261,7 +263,7 @@ def pytest_addoption(parser):
261263
help='Ignore Report Portal errors (exit otherwise)')
262264

263265
parser.addini(
264-
'rp_ignore_tags',
266+
'rp_ignore_attributes',
265267
type='args',
266268
help='Ignore specified pytest markers, i.e parametrize')
267269

pytest_reportportal/service.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from _pytest.unittest import TestCaseFunction, UnitTestCase
2626

2727
from reportportal_client import ReportPortalService
28+
from reportportal_client.service import _dict_to_payload
2829
from six import with_metaclass
2930
from six.moves import queue
3031

@@ -83,7 +84,7 @@ def __init__(self):
8384
self._item_parts = {}
8485
self._loglevels = ('TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR')
8586
self.ignore_errors = True
86-
self.ignored_tags = []
87+
self.ignored_attributes = []
8788
self.log_batch_size = 20
8889
self.log_item_id = None
8990
self.parent_item_id = None
@@ -112,17 +113,17 @@ def init_service(self,
112113
uuid,
113114
log_batch_size,
114115
ignore_errors,
115-
ignored_tags,
116+
ignored_attributes,
116117
verify_ssl=True,
117118
retries=0):
118119
"""Update self.rp with the instance of the ReportPortalService."""
119120
self._errors = queue.Queue()
120121
if self.rp is None:
121122
self.ignore_errors = ignore_errors
122-
self.ignored_tags = ignored_tags
123+
self.ignored_attributes = ignored_attributes
123124
if self.rp_supports_parameters:
124-
self.ignored_tags = list(
125-
set(ignored_tags).union({'parametrize'}))
125+
self.ignored_attributes = list(
126+
set(ignored_attributes).union({'parametrize'}))
126127
log.debug('ReportPortal - Init service: endpoint=%s, '
127128
'project=%s, uuid=%s', endpoint, project, uuid)
128129
self.rp = ReportPortalService(
@@ -143,15 +144,14 @@ def start_launch(self,
143144
launch_name,
144145
mode=None,
145146
description=None,
147+
attributes=None,
146148
**kwargs):
147149
self._stop_if_necessary()
148150
if self.rp is None:
149151
return
150152

151-
system_info = self.rp.get_system_information(self._agent_name)
152-
system_info['system'] = True
153153
sl_pt = {
154-
'attributes': system_info,
154+
'attributes': self._get_launch_attributes(attributes),
155155
'name': launch_name,
156156
'start_time': timestamp(),
157157
'description': description,
@@ -449,9 +449,22 @@ def _get_item_dirs(item):
449449

450450
return dir_list
451451

452+
def _get_launch_attributes(self, ini_attrs):
453+
"""Generate launch attributes in the format supported by the client.
454+
455+
:param list ini_attrs: List for attributes from the pytest.ini file
456+
"""
457+
attributes = ini_attrs or []
458+
459+
system_info = self.rp.get_system_information(self._agent_name)
460+
system_info['system'] = True
461+
system_attributes = _dict_to_payload(system_info)
462+
463+
return attributes + system_attributes
464+
452465
def _get_item_markers(self, item):
453466
# Try to extract names of @pytest.mark.* decorators used for test item
454-
# and exclude those which present in rp_ignore_tags parameter
467+
# and exclude those which present in rp_ignore_attributes parameter
455468
def get_marker_value(item, keyword):
456469
try:
457470
marker = item.get_closest_marker(keyword)
@@ -466,13 +479,13 @@ def get_marker_value(item, keyword):
466479
get_marker = getattr(item, "get_closest_marker")
467480
except AttributeError:
468481
get_marker = getattr(item, "get_marker")
469-
tags = [{"value": get_marker_value(item, k)}
470-
for k in item.keywords if get_marker(k) is not None
471-
and k not in self.ignored_tags]
482+
attributes = [{"value": get_marker_value(item, k)}
483+
for k in item.keywords if get_marker(k) is not None
484+
and k not in self.ignored_attributes]
472485

473-
tags.extend([{"value": tag}
474-
for tag in item.session.config.getini('rp_tests_tags')])
475-
return tags
486+
attributes.extend([{"value": tag} for tag in
487+
item.session.config.getini('rp_tests_attributes')])
488+
return attributes
476489

477490
def _get_parameters(self, item):
478491
return item.callspec.params if hasattr(item, 'callspec') else None

tests/test_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import pytest
77

88

9-
def test_item_tags(rp_service):
10-
"""Test that item tags are generated in a supported way."""
9+
def test_item_attributes(rp_service):
10+
"""Test that item attributes are generated in a supported way."""
1111
rp_service.is_item_update_supported = mock.Mock(return_value=False)
1212

1313
def getini(option):
14-
if option == 'rp_tests_tags':
14+
if option == 'rp_tests_attributes':
1515
return ['ini_marker']
1616

1717
def get_closest_marker(name):

0 commit comments

Comments
 (0)