Skip to content

Commit f5e61d4

Browse files
authored
Merge pull request #209 from iivanou/key_value_attributes
Allow passing key/value attributes to RP
2 parents a28f9cf + 38561b6 commit f5e61d4

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The following parameters are optional:
8080

8181
- :code:`rp_launch = AnyLaunchName` - launch name (could be overridden
8282
by pytest --rp-launch option, default value is 'Pytest Launch')
83-
- :code:`rp_launch_attributes = 'PyTest' 'Smoke'` - list of attributes for launch
83+
- :code:`rp_launch_attributes = 'PyTest' 'Smoke' 'Env:Python3'` - list of attributes for launch
8484
- :code:`rp_tests_attributes = 'PyTest' 'Smoke'` - list of attributes that will be added for each item in the launch
8585
- :code:`rp_launch_description = 'Smoke test'` - launch description (could be overridden
8686
by pytest --rp-launch-description option, default value is '')

pytest_reportportal/plugin.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ def is_master(config):
4040
return not hasattr(config, 'slaveinput')
4141

4242

43+
def get_launch_attributes(rp_launch_attributes):
44+
"""Generate list of launch attributes for RP.
45+
46+
:param list rp_launch_attributes: rp_launch_attributes option value
47+
:return list: List of dictionaries to be passed to the
48+
RP Python client
49+
"""
50+
launch_attrs = []
51+
for rp_attr in rp_launch_attributes:
52+
try:
53+
key, value = rp_attr.split(':')
54+
attr_dict = {'key': key, 'value': value}
55+
except ValueError:
56+
attr_dict = {'value': rp_attr}
57+
58+
if all(value for value in attr_dict.values()):
59+
launch_attrs.append(attr_dict)
60+
continue
61+
log.debug('Failed to process "{0}" attribute, attribute value'
62+
' should not be empty.'.format(rp_attr))
63+
return launch_attrs
64+
65+
4366
@pytest.mark.optionalhook
4467
def pytest_configure_node(node):
4568
"""
@@ -78,8 +101,8 @@ def pytest_sessionstart(session):
78101
retries=int(session.config.getini('retries')),
79102
)
80103

81-
attributes = [{'value': tag} for tag in
82-
session.config.getini('rp_launch_attributes')]
104+
attributes = get_launch_attributes(
105+
session.config.getini('rp_launch_attributes'))
83106
session.config.py_test_service.start_launch(
84107
session.config.option.rp_launch,
85108
attributes=attributes,

tests/test_plugin.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
import pytest
88
from requests.exceptions import RequestException
99

10-
from pytest_reportportal.listener import RPReportListener
11-
from pytest_reportportal.plugin import pytest_configure, pytest_sessionstart
10+
from pytest_reportportal.plugin import (
11+
get_launch_attributes,
12+
pytest_configure,
13+
pytest_sessionstart
14+
)
1215

1316

1417
@mock.patch('pytest_reportportal.plugin.requests.get')
@@ -71,3 +74,10 @@ def test_uuid_env_var_override(mocked_session):
7174
pytest_sessionstart(mocked_session)
7275
args, kwargs = mocked_session.config.py_test_service.init_service.call_args
7376
assert kwargs.get('uuid') == 'foobar'
77+
78+
79+
def test_get_launch_attributes():
80+
"""Test get_launch_attributes functionality."""
81+
expected_out = [{'value': 'Tag'}, {'key': 'Key', 'value': 'Value'}]
82+
out = get_launch_attributes(['Tag', 'Key:Value', ''])
83+
assert expected_out == out

0 commit comments

Comments
 (0)