Skip to content

Commit a702d60

Browse files
author
Roman Plevka
authored
implement using of custom parent_item for the pytest session
1 parent 291fe4d commit a702d60

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ The following parameters are optional:
8383
by pytest --rp-launch option, default value is 'Pytest Launch')
8484
- :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)
8585
- :code:`rp_launch_attributes = 'PyTest' 'Smoke' 'Env:Python3'` - list of attributes for launch
86+
- :code:`rp_parent_item_id = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` - id of the existing test item for session to use as parent item for the tests (the session will not handle the lifecycle of the given test item)
8687
- :code:`rp_tests_attributes = 'PyTest' 'Smoke'` - list of attributes that will be added for each item in the launch
8788
- :code:`rp_launch_description = 'Smoke test'` - launch description (could be overridden
8889
by pytest --rp-launch-description option, default value is '')

pytest_reportportal/plugin.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def pytest_sessionstart(session):
8282
'rp_ignore_attributes'),
8383
verify_ssl=session.config.getini('rp_verify_ssl'),
8484
retries=int(session.config.getini('retries')),
85+
parent_item_id=session.config.option.rp_parent_item_id or None,
8586
)
8687
except ResponseError as response_error:
8788
log.warning('Failed to initialize reportportal-client service. '
@@ -202,6 +203,11 @@ def pytest_configure(config):
202203
if not config.option.rp_rerun:
203204
config.option.rp_rerun = config.getini('rp_rerun')
204205

206+
if not config.option.rp_parent_item_id:
207+
config.option.rp_parent_item_id = config.getini('rp_parent_item_id')
208+
if not config.option.rp_launch_id:
209+
config.option.rp_launch_id = config.getini('rp_launch_id')
210+
205211
if is_master(config):
206212
config.py_test_service = PyTestServiceClass()
207213
else:
@@ -279,6 +285,13 @@ def pytest_addoption(parser):
279285
dest='rp_rerun_of',
280286
help='ID of the launch to be marked as a rerun '
281287
'(use only with rp_rerun=True)')
288+
group.addoption(
289+
'--rp-parent-item-id',
290+
action='store',
291+
dest='rp_parent_item_id',
292+
help="Create all test item as child items of the given "
293+
"(already existing) item.")
294+
282295
group.addoption(
283296
'--reportportal',
284297
action='store_true',
@@ -418,6 +431,12 @@ def pytest_addoption(parser):
418431
default=True,
419432
help='Adding tag with issue id to the test')
420433

434+
parser.addini(
435+
'rp_parent_item_id',
436+
default=None,
437+
help="Create all test item as child items of the given "
438+
"(already existing) item.")
439+
421440
parser.addini(
422441
'retries',
423442
default='0',

pytest_reportportal/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ def init_service(self,
142142
ignored_attributes,
143143
verify_ssl=True,
144144
custom_launch=None,
145+
parent_item_id=None,
145146
retries=0):
146147
"""Update self.rp with the instance of the ReportPortalService."""
147148
self._errors = queue.Queue()
148149
if self.rp is None:
149150
self.ignore_errors = ignore_errors
150151
self.ignored_attributes = ignored_attributes
152+
self.parent_item_id = parent_item_id
151153
if self.rp_supports_parameters:
152154
self.ignored_attributes = list(
153155
set(ignored_attributes).union({'parametrize'}))
@@ -298,7 +300,6 @@ def start_pytest_item(self, test_item=None):
298300
if self.rp is None:
299301
return
300302

301-
self.parent_item_id = None
302303
for part in self._item_parts[test_item]:
303304
if self._hier_parts[part]["start_flag"]:
304305
self.parent_item_id = self._hier_parts[part]["item_id"]

0 commit comments

Comments
 (0)