Skip to content

Commit 291fe4d

Browse files
author
Roman Plevka
authored
implement rerun functionality
1 parent f1d9f63 commit 291fe4d

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

pytest_reportportal/plugin.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def pytest_sessionstart(session):
9696
session.config.py_test_service.start_launch(
9797
session.config.option.rp_launch,
9898
attributes=attributes,
99-
description=session.config.option.rp_launch_description
99+
description=session.config.option.rp_launch_description,
100+
rerun=session.config.option.rp_rerun,
101+
rerun_of=session.config.option.rp_rerun_of
100102
)
101103
if session.config.pluginmanager.hasplugin('xdist'):
102104
wait_launch(session.config.py_test_service.rp)
@@ -185,12 +187,21 @@ def pytest_configure(config):
185187

186188
if not config.option.rp_launch:
187189
config.option.rp_launch = config.getini('rp_launch')
190+
188191
if not config.option.rp_launch_description:
189192
config.option.rp_launch_description = config.\
190193
getini('rp_launch_description')
191194
if not config.option.rp_launch_id:
192195
config.option.rp_launch_id = config.getini('rp_launch_id')
193196

197+
if not config.option.rp_rerun_of:
198+
config.option.rp_rerun_of = config.getini('rp_rerun_of')
199+
if config.option.rp_rerun_of:
200+
config.option.rp_rerun = True
201+
else:
202+
if not config.option.rp_rerun:
203+
config.option.rp_rerun = config.getini('rp_rerun')
204+
194205
if is_master(config):
195206
config.py_test_service = PyTestServiceClass()
196207
else:
@@ -257,7 +268,17 @@ def pytest_addoption(parser):
257268
dest='rp_launch_description',
258269
help='Launch description (overrides '
259270
'rp_launch_description config option)')
260-
271+
group.addoption(
272+
'--rp-rerun',
273+
action='store_true',
274+
dest='rp_rerun',
275+
help='Marks the launch as the rerun')
276+
group.addoption(
277+
'--rp-rerun-of',
278+
action='store',
279+
dest='rp_rerun_of',
280+
help='ID of the launch to be marked as a rerun '
281+
'(use only with rp_rerun=True)')
261282
group.addoption(
262283
'--reportportal',
263284
action='store_true',
@@ -401,3 +422,14 @@ def pytest_addoption(parser):
401422
'retries',
402423
default='0',
403424
help='Amount of retries for performing REST calls to RP server')
425+
426+
parser.addini(
427+
'rp_rerun',
428+
default=False,
429+
help='Marks the launch as the rerun')
430+
431+
parser.addini(
432+
'rp_rerun_of',
433+
default='',
434+
help='ID of the launch to be marked as a rerun '
435+
'(use only with rp_rerun=True)')

pytest_reportportal/service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def init_service(self,
161161
log_batch_size=log_batch_size,
162162
retries=retries,
163163
verify_ssl=verify_ssl,
164-
launch_id=custom_launch
164+
launch_id=custom_launch,
165165
)
166166
self.project_settings = None
167167
if self.rp and hasattr(self.rp, "get_project_settings"):
@@ -175,6 +175,8 @@ def start_launch(self,
175175
mode=None,
176176
description=None,
177177
attributes=None,
178+
rerun=False,
179+
rerun_of=None,
178180
**kwargs):
179181
"""
180182
Launch test items.
@@ -195,6 +197,8 @@ def start_launch(self,
195197
'start_time': timestamp(),
196198
'description': description,
197199
'mode': mode,
200+
'rerun': rerun,
201+
'rerunOf': rerun_of
198202
}
199203
log.debug('ReportPortal - Start launch: request_body=%s', sl_pt)
200204
item_id = self.rp.start_launch(**sl_pt)
@@ -300,7 +304,6 @@ def start_pytest_item(self, test_item=None):
300304
self.parent_item_id = self._hier_parts[part]["item_id"]
301305
continue
302306
self._hier_parts[part]["start_flag"] = True
303-
304307
payload = {
305308
'name': self._get_item_name(part),
306309
'description': self._get_item_description(part),

0 commit comments

Comments
 (0)