Skip to content

Commit f271aaa

Browse files
author
Roman Plevka
authored
Implement rp_launch_id parameter to specify launch to be used by the session
1 parent d933baa commit f271aaa

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ The following parameters are optional:
8181

8282
- :code:`rp_launch = AnyLaunchName` - launch name (could be overridden
8383
by pytest --rp-launch option, default value is 'Pytest Launch')
84+
- :code:`rp_launch_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` - id of the existing launch (the session will not handle the lifecycle of the given launch)
8485
- :code:`rp_launch_attributes = 'PyTest' 'Smoke' 'Env:Python3'` - list of attributes for launch
8586
- :code:`rp_tests_attributes = 'PyTest' 'Smoke'` - list of attributes that will be added for each item in the launch
8687
- :code:`rp_launch_description = 'Smoke test'` - launch description (could be overridden

pytest_reportportal/plugin.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def pytest_sessionstart(session):
6969
if session.config._reportportal_configured is False:
7070
# Stop now if the plugin is not properly configured
7171
return
72-
7372
if is_master(session.config):
7473
try:
7574
session.config.py_test_service.init_service(
@@ -78,6 +77,7 @@ def pytest_sessionstart(session):
7877
uuid=getenv('RP_UUID') or session.config.getini('rp_uuid'),
7978
log_batch_size=int(session.config.getini('rp_log_batch_size')),
8079
ignore_errors=bool(session.config.getini('rp_ignore_errors')),
80+
custom_launch=session.config.getini('rp_launch_id') or None,
8181
ignored_attributes=session.config.getini(
8282
'rp_ignore_attributes'),
8383
verify_ssl=session.config.getini('rp_verify_ssl'),
@@ -92,13 +92,14 @@ def pytest_sessionstart(session):
9292

9393
attributes = gen_attributes(
9494
session.config.getini('rp_launch_attributes'))
95-
session.config.py_test_service.start_launch(
96-
session.config.option.rp_launch,
97-
attributes=attributes,
98-
description=session.config.option.rp_launch_description
99-
)
100-
if session.config.pluginmanager.hasplugin('xdist'):
101-
wait_launch(session.config.py_test_service.rp)
95+
if not session.config.getini('rp_launch_id'):
96+
session.config.py_test_service.start_launch(
97+
session.config.option.rp_launch,
98+
attributes=attributes,
99+
description=session.config.option.rp_launch_description
100+
)
101+
if session.config.pluginmanager.hasplugin('xdist'):
102+
wait_launch(session.config.py_test_service.rp)
102103

103104

104105
def pytest_collection_finish(session):
@@ -141,7 +142,8 @@ def pytest_sessionfinish(session):
141142
return
142143

143144
if is_master(session.config):
144-
session.config.py_test_service.finish_launch()
145+
if not session.config.getini('rp_launch_id'):
146+
session.config.py_test_service.finish_launch()
145147

146148

147149
def pytest_configure(config):
@@ -241,6 +243,12 @@ def pytest_addoption(parser):
241243
action='store',
242244
dest='rp_launch',
243245
help='Launch name (overrides rp_launch config option)')
246+
group.addoption(
247+
'--rp-launch-id',
248+
action='store',
249+
dest='rp_launch_id',
250+
help='Use already existing launch-id. The plugin won\'t control the '
251+
'Launch status (overrides rp_launch_id config option)')
244252
group.addoption(
245253
'--rp-launch-description',
246254
action='store',
@@ -286,6 +294,12 @@ def pytest_addoption(parser):
286294
default='Pytest Launch',
287295
help='Launch name')
288296

297+
parser.addini(
298+
'rp_launch_id',
299+
default=None,
300+
help='Use already existing launch-id. The plugin won\'t control '
301+
'the Launch status')
302+
289303
parser.addini(
290304
'rp_launch_attributes',
291305
type='args',

pytest_reportportal/service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def init_service(self,
141141
ignore_errors,
142142
ignored_attributes,
143143
verify_ssl=True,
144+
custom_launch=None,
144145
retries=0):
145146
"""Update self.rp with the instance of the ReportPortalService."""
146147
self._errors = queue.Queue()
@@ -159,7 +160,8 @@ def init_service(self,
159160
token=uuid,
160161
log_batch_size=log_batch_size,
161162
retries=retries,
162-
verify_ssl=verify_ssl
163+
verify_ssl=verify_ssl,
164+
launch_id=custom_launch
163165
)
164166
self.project_settings = None
165167
if self.rp and hasattr(self.rp, "get_project_settings"):

0 commit comments

Comments
 (0)