Skip to content

Commit cabad69

Browse files
authored
Merge pull request #15 from vakulich/rp_launch_config
Add launch name config option and tags for test items
2 parents d0bfb85 + e271ff8 commit cabad69

File tree

4 files changed

+81
-46
lines changed

4 files changed

+81
-46
lines changed

README.rst

Lines changed: 35 additions & 7 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,17 +45,23 @@ 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:
5253

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
5358

54-
Logging
55-
~~~~~~~
59+
60+
Examples
61+
~~~~~~~~
5662

5763
For logging of the test item flow to Report Portal, please, use the python
58-
logging handler privided by plugin like bellow:
64+
logging handler provided by plugin like bellow:
5965

6066
.. code-block:: python
6167
@@ -96,11 +102,33 @@ logging handler privided by plugin like bellow:
96102
# This debug message will not be sent to the Report Portal.
97103
logger.debug("Case1. Debug message")
98104
105+
Plugin can report doc-strings of tests as :code:`descriptions`:
106+
107+
.. code-block:: python
108+
109+
def test_one():
110+
"""
111+
Description of the test case which will be sent to Report Portal
112+
"""
113+
pass
114+
115+
Pytest markers will be attached as :code:`tags` to Report Portal items.
116+
In the following example tags 'linux' and 'win32' will be used:
117+
118+
.. code-block:: python
119+
120+
import pytest
121+
122+
@pytest.mark.win32
123+
@pytest.mark.linux
124+
def test_one():
125+
pass
126+
99127
100128
Launching
101129
~~~~~~~~~
102130

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

105133
.. code-block:: bash
106134

pytest_reportportal/plugin.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def pytest_runtest_makereport(self, item, call):
2929
)
3030

3131
if report.when == "setup":
32-
3332
# when function pytest_setup is called,
3433
# test item session will be started in RP
3534
PyTestService.start_pytest_item(item)
@@ -58,45 +57,38 @@ def pytest_runtest_makereport(self, item, call):
5857

5958

6059
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)
60+
PyTestService.init_service(
61+
project=session.config.getini("rp_project"),
62+
endpoint=session.config.getini("rp_endpoint"),
63+
uuid=session.config.getini("rp_uuid"),
64+
)
65+
66+
PyTestService.start_launch(
67+
session.config.option.rp_launch,
68+
tags=session.config.getini("rp_launch_tags"),
69+
description=session.config.getini("rp_launch_description"),
70+
)
7671

7772

7873
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")
74+
# FixMe: currently method of RP api takes the string parameter
75+
# so it is hardcoded
76+
PyTestService.finish_launch(status="RP_Launch")
8477

8578

8679
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()
80+
if not config.option.rp_launch:
81+
config.option.rp_launch = config.getini("rp_launch")
9182

92-
if hasattr(config, "_reporter"):
93-
config.pluginmanager.register(config._reporter)
83+
# set Pytest_Reporter and configure it
84+
config._reporter = RP_Report_Listener()
85+
86+
if hasattr(config, "_reporter"):
87+
config.pluginmanager.register(config._reporter)
9488

9589

9690
def pytest_unconfigure(config):
97-
rp_launch = config.getoption("rp_launch")
98-
if rp_launch:
99-
PyTestService.terminate_service()
91+
PyTestService.terminate_service()
10092

10193
if hasattr(config, "_reporter"):
10294
reporter = config._reporter
@@ -111,21 +103,31 @@ def pytest_addoption(parser):
111103
"--rp-launch",
112104
action="store",
113105
dest="rp_launch",
114-
help="The Launch name for RP")
106+
help="Launch name (overrides rp_launch config option)")
115107

116108
parser.addini(
117109
"rp_uuid",
118-
help="Uid of RP user")
110+
help="UUID")
119111

120112
parser.addini(
121113
"rp_endpoint",
122-
help="RP server")
114+
help="Server endpoint")
123115

124116
parser.addini(
125117
"rp_project",
126-
help="RP Project")
118+
help="Project name")
119+
120+
parser.addini(
121+
"rp_launch",
122+
default="Pytest Launch",
123+
help="Launch name")
127124

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

pytest_reportportal/service.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from time import time
44

55
from six import with_metaclass
6+
from _pytest.mark import MarkMapping
67

78
from reportportal_client import ReportPortalServiceAsync
89

@@ -53,13 +54,13 @@ def terminate_service(self):
5354
self.RP.terminate()
5455

5556
def start_launch(
56-
self, launch_name, mode=None, tags=None):
57+
self, launch_name, mode=None, tags=None, description=None):
5758
# In next versions launch object(suite, testcase)
5859
# could be set as parameter
5960
sl_pt = {
6061
"name": launch_name,
6162
"start_time": timestamp(),
62-
"description": 'Pytest Launch',
63+
"description": description,
6364
"mode": mode,
6465
"tags": tags
6566
}
@@ -76,10 +77,14 @@ def start_pytest_item(self, test_item=None):
7677
except AttributeError:
7778
# doctest has no `function` attribute
7879
item_description = test_item.reportinfo()[2]
80+
81+
# extract names of @pytest.mark.* decorators used for test item
82+
item_tags = list(MarkMapping(test_item.keywords)._mymarks)
83+
7984
start_rq = {
8085
"name": test_item.name,
8186
"description": item_description,
82-
"tags": ['PyTest Item Tag'],
87+
"tags": item_tags,
8388
"start_time": timestamp(),
8489
"item_type": "TEST"
8590
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def read_file(fname):
1515
setup(
1616
name="pytest-reportportal",
1717
version=version,
18-
description="Agent for Reproting results of tests to the Report Portal server",
18+
description="Agent for Reporting results of tests to the Report Portal server",
1919
long_description=read_file("README.rst") + "\n\n",
2020
author="Pavel Papou",
2121
author_email="[email protected]",

0 commit comments

Comments
 (0)