Skip to content

Commit 0bd62d5

Browse files
committed
Configure RP Launch Name from config or CLI
Changes: - added rp_launch and rp_launch_description config options; - rp_launch option has a default value so it is no longer mandatory; - CLI option --rp_launch will override rp_launch config option; - updated help strings for options and README file.
1 parent f0de9b0 commit 0bd62d5

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ any one using pytest command line option:
3333
3434
The :code:`pytest.ini` file should have next mandatory fields:
3535

36-
- :code:`rp_uuid` - number could be found in the User profile section
36+
- :code:`rp_uuid` - value could be found in the User Profile section
3737
- :code:`rp_project` - name of project in Report Potal
3838
- :code:`rp_endpoint` - address of Report Portal Server
3939

@@ -45,10 +45,16 @@ Example of :code:`pytest.ini`:
4545
rp_uuid = fb586627-32be-47dd-93c1-678873458a5f
4646
rp_endpoint = http://192.168.1.10:8080
4747
rp_project = user_personal
48+
rp_launch = AnyLaunchName
4849
rp_launch_tags = 'PyTest' 'Smoke'
50+
rp_launch_description = 'Smoke test'
4951
50-
Also launch tags could be added, but this parapmeter is not
51-
mandatory :code:`rp_launch_tags = 'PyTest' 'Report_Portal'`.
52+
The following parapmeters are optional:
53+
54+
- :code:`rp_launch = AnyLaunchName` - launch name (could be overriden
55+
by pytest --rp-launch option, default value is 'Pytest Launch')
56+
- :code:`rp_launch_tags = 'PyTest' 'Smoke'` - list of tags
57+
- :code:`rp_launch_description = 'Smoke test'` - launch description
5258

5359

5460
Logging
@@ -100,7 +106,7 @@ logging handler privided by plugin like bellow:
100106
Launching
101107
~~~~~~~~~
102108

103-
To run test with Report Portal you need to specify neme of :code:`launch`:
109+
To run test with Report Portal you can specify name of :code:`launch`:
104110

105111
.. code-block:: bash
106112

pytest_reportportal/plugin.py

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,45 +58,38 @@ def pytest_runtest_makereport(self, item, call):
5858

5959

6060
def pytest_sessionstart(session):
61-
config = session.config
62-
if config.option.rp_launch:
63-
# get config parameters if rp_launch option is set
64-
rp_uuid = config.getini("rp_uuid")
65-
rp_project = config.getini("rp_project")
66-
rp_endpoint = config.getini("rp_endpoint")
67-
rp_launch_tags = config.getini("rp_launch_tags")
68-
# initialize PyTest
69-
PyTestService.init_service(
70-
project=rp_project,
71-
endpoint=rp_endpoint,
72-
uuid=rp_uuid)
73-
launch_name = config.getoption("rp_launch")
74-
75-
PyTestService.start_launch(launch_name, tags=rp_launch_tags)
61+
PyTestService.init_service(
62+
project=session.config.getini("rp_project"),
63+
endpoint=session.config.getini("rp_endpoint"),
64+
uuid=session.config.getini("rp_uuid"),
65+
)
66+
67+
PyTestService.start_launch(
68+
session.config.option.rp_launch,
69+
tags=session.config.getini("rp_launch_tags"),
70+
description=session.config.getini("rp_launch_description"),
71+
)
7672

7773

7874
def pytest_sessionfinish(session):
79-
config = session.config
80-
if config.option.rp_launch:
81-
# FixMe: currently method of RP api takes the string parameter
82-
# so it is hardcoded
83-
PyTestService.finish_launch(status="RP_Launch")
75+
# FixMe: currently method of RP api takes the string parameter
76+
# so it is hardcoded
77+
PyTestService.finish_launch(status="RP_Launch")
8478

8579

8680
def pytest_configure(config):
87-
rp_launch = config.getoption("rp_launch")
88-
if rp_launch:
89-
# set Pytest_Reporter and configure it
90-
config._reporter = RP_Report_Listener()
81+
if not config.option.rp_launch:
82+
config.option.rp_launch = config.getini("rp_launch")
83+
84+
# set Pytest_Reporter and configure it
85+
config._reporter = RP_Report_Listener()
9186

92-
if hasattr(config, "_reporter"):
93-
config.pluginmanager.register(config._reporter)
87+
if hasattr(config, "_reporter"):
88+
config.pluginmanager.register(config._reporter)
9489

9590

9691
def pytest_unconfigure(config):
97-
rp_launch = config.getoption("rp_launch")
98-
if rp_launch:
99-
PyTestService.terminate_service()
92+
PyTestService.terminate_service()
10093

10194
if hasattr(config, "_reporter"):
10295
reporter = config._reporter
@@ -111,21 +104,31 @@ def pytest_addoption(parser):
111104
"--rp-launch",
112105
action="store",
113106
dest="rp_launch",
114-
help="The Launch name for RP")
107+
help="Launch name (overrides rp_launch config option)")
115108

116109
parser.addini(
117110
"rp_uuid",
118-
help="Uid of RP user")
111+
help="UUID")
119112

120113
parser.addini(
121114
"rp_endpoint",
122-
help="RP server")
115+
help="Server endpoint")
123116

124117
parser.addini(
125118
"rp_project",
126-
help="RP Project")
119+
help="Project name")
120+
121+
parser.addini(
122+
"rp_launch",
123+
default="Pytest Launch",
124+
help="Launch name")
127125

128126
parser.addini(
129127
"rp_launch_tags",
130128
type="args",
131-
help="Tags for of RP Launch, i.e Perfomance Regression")
129+
help="Launch tags, i.e Performance Regression")
130+
131+
parser.addini(
132+
"rp_launch_description",
133+
default="",
134+
help="Launch description")

pytest_reportportal/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def terminate_service(self):
5353
self.RP.terminate()
5454

5555
def start_launch(
56-
self, launch_name, mode=None, tags=None):
56+
self, launch_name, mode=None, tags=None, description=None):
5757
# In next versions launch object(suite, testcase)
5858
# could be set as parameter
5959
sl_pt = {
6060
"name": launch_name,
6161
"start_time": timestamp(),
62-
"description": 'Pytest Launch',
62+
"description": description,
6363
"mode": mode,
6464
"tags": tags
6565
}

0 commit comments

Comments
 (0)