Skip to content

Commit 970e96d

Browse files
authored
Add env var override for rp_uuid
1 parent 16e3201 commit 970e96d

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dist/
1313
.installed.cfg
1414
*.egg
1515
MANIFEST
16+
.eggs
1617

1718
# Installer logs
1819
pip-log.txt

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Example of :code:`pytest.ini`:
7474
rp_ignore_errors = True
7575
rp_ignore_attributes = 'xfail' 'usefixture'
7676
77+
- The :code:`rp_uuid` can also be set with the environment variable `RP_UUID`. This will override the value set for :code:`rp_uuid` in pytest.ini
78+
7779
The following parameters are optional:
7880

7981
- :code:`rp_launch = AnyLaunchName` - launch name (could be overridden

pytest_reportportal/plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# and/or modify it under the terms of the GPL licence
33

44
import logging
5+
from os import getenv
56
import dill as pickle
67
import pkg_resources
78
import pytest
@@ -52,7 +53,7 @@ def pytest_sessionstart(session):
5253
session.config.py_test_service.init_service(
5354
project=session.config.getini('rp_project'),
5455
endpoint=session.config.getini('rp_endpoint'),
55-
uuid=session.config.getini('rp_uuid'),
56+
uuid=getenv('RP_UUID') or session.config.getini('rp_uuid'),
5657
log_batch_size=int(session.config.getini('rp_log_batch_size')),
5758
ignore_errors=bool(session.config.getini('rp_ignore_errors')),
5859
ignored_attributes=session.config.getini('rp_ignore_attributes'),
@@ -106,7 +107,7 @@ def pytest_configure(config):
106107

107108
project = config.getini('rp_project')
108109
endpoint = config.getini('rp_endpoint')
109-
uuid = config.getini('rp_uuid')
110+
uuid = getenv('RP_UUID') or config.getini('rp_uuid')
110111
ignore_errors = config.getini('rp_ignore_errors')
111112
config._reportportal_configured = all([project, endpoint, uuid])
112113

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def read_file(fname):
88
return f.read()
99

1010

11-
version = '5.0.3'
11+
version = '5.0.4'
1212

1313

1414
requirements = [

tests/test_plugin.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""This modules includes unit tests for the plugin."""
22

33
from six.moves import mock
4+
import os
45

56
from delayed_assert import expect, assert_expectations
67
import pytest
78
from requests.exceptions import RequestException
89

910
from pytest_reportportal.listener import RPReportListener
10-
from pytest_reportportal.plugin import pytest_configure
11+
from pytest_reportportal.plugin import pytest_configure, pytest_sessionstart
1112

1213

1314
@mock.patch('pytest_reportportal.plugin.requests.get')
@@ -138,3 +139,18 @@ def iter_markers(name=None):
138139
expect(mocked_item.add_marker.call_args[0][0] == "issue:456823",
139140
"item.add_marker called with incorrect parameters")
140141
assert_expectations()
142+
143+
144+
@mock.patch.dict(os.environ, {'RP_UUID': 'foobar'})
145+
def test_uuid_env_var_override(mocked_session):
146+
"""
147+
Test setting RP_UUID env variable overrides the rp_uuid config value
148+
:param mocked_session: pytest fixture
149+
"""
150+
mocked_session.config.py_test_service = mock.Mock()
151+
mocked_session.config.option = mock.Mock()
152+
mocked_session.config.pluginmanager = mock.Mock()
153+
mocked_session.config.py_test_service.init_service = mock.Mock()
154+
pytest_sessionstart(mocked_session)
155+
args, kwargs = mocked_session.config.py_test_service.init_service.call_args
156+
assert kwargs.get('uuid') == 'foobar'

tests/test_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ def test_get_item_parameters(rp_service):
4242
expect(rp_service._get_parameters(test_item) is None)
4343

4444
assert_expectations()
45-

0 commit comments

Comments
 (0)