Skip to content

Commit dcc539b

Browse files
author
Dzmitry Humianiuk
authored
Merge branch 'master' into fix-readme-rendering
2 parents 4ca0eeb + 8927e8e commit dcc539b

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ The following parameters are optional:
7777
- :code:`rp_hierarchy_parametrize = True` - Enables hierarchy parametrized tests, default `False`. Doesn't support 'xdist' plugin.
7878
- :code:`rp_hierarchy_dirs_level = 0` - Directory starting hierarchy level (from pytest.ini level) (default `0`)
7979
- :code:`rp_issue_marks = 'xfail' 'issue'` - Pytest marks that could be used to get issue information (id, type, reason)
80-
- :code:`rp_issue_system_url = https://bugzilla.olympus.f5net.com/show_bug.cgi?id=` - URL to get issue description (issue id from pytest mark will be added to this URL)
80+
- :code:`rp_issue_system_url = http://bugzilla.some.com/show_bug.cgi?id={%issue_id}` - issue URL (issue_id will be filled by parameter from pytest mark)
8181
- :code:`rp_verify_ssl = True` - Verify SSL when connecting to the server
82+
- :code:`rp_display_suite_test_file = True` In case of True, include the suite's relative file path in the launch name as a convention of "<RELATIVE_FILE_PATH>::<SUITE_NAME>". In case of False, set the launch name to be the suite name only - this flag is relevant only when "rp_hierarchy_module" flag is set to False
83+
8284

8385
If you like to override the above parameters from command line, or from CI environment based on your build, then pass
8486
- :code:`-o "rp_launch_tags=Smoke Tests"` during invocation.

pytest_reportportal/listener.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import cgi
21
import pytest
32
import logging
3+
try:
4+
from html import escape # python3
5+
except ImportError:
6+
from cgi import escape # python2
47

58

69
try:
@@ -46,8 +49,7 @@ def pytest_runtest_makereport(self, item):
4649

4750
if report.longrepr:
4851
self.PyTestService.post_log(
49-
# Used for support python 2.7
50-
cgi.escape(report.longreprtext),
52+
escape(report.longreprtext),
5153
loglevel='ERROR',
5254
)
5355

@@ -101,17 +103,17 @@ def _add_issue_info(self, item, report):
101103
issue_ids = [issue_ids]
102104
comment += "\n" if comment else ""
103105
comment += "Issues:"
104-
105106
for issue_id in issue_ids:
106-
comment += " [{}]({}{})".format(issue_id, url, issue_id) if url else " {}".format(issue_id)
107+
template = (" [{issue_id}]" + "({})".format(url)) if url else " {issue_id}"
108+
comment += template.format(issue_id=issue_id)
107109

108110
if "issue_type" in mark.kwargs:
109111
issue_type = mark.kwargs["issue_type"]
110112

111-
if comment:
112-
self.issue['comment'] = comment
113-
114-
if issue_type and self.PyTestService.issue_types and (issue_type in self.PyTestService.issue_types):
113+
if issue_type and self.PyTestService.issue_types \
114+
and (issue_type in self.PyTestService.issue_types):
115+
if comment:
116+
self.issue['comment'] = comment
115117
self.issue['issue_type'] = self.PyTestService.issue_types[issue_type]
116118
# self.issue['ignoreAnalyzer'] = True ???
117119
elif (report.when == 'setup') and report.skipped:

pytest_reportportal/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,11 @@ def pytest_addoption(parser):
297297
default=True,
298298
type='bool',
299299
help='Verify HTTPS calls')
300+
301+
parser.addini(
302+
'rp_display_suite_test_file',
303+
default=True,
304+
type='bool',
305+
help="In case of True, include the suite's relative file path in the launch name as a convention of "
306+
"'<RELATIVE_FILE_PATH>::<SUITE_NAME>'. In case of False, set the launch name to be the suite name "
307+
"only - this flag is relevant only when 'rp_hierarchy_module' flag is set to False")

pytest_reportportal/service.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import logging
22
import sys
33
import traceback
4-
import pytest
5-
import pkg_resources
6-
74
from time import time
8-
from six import with_metaclass
9-
from six.moves import queue
105

11-
from _pytest.main import Session
12-
from _pytest.python import Class, Function, Instance, Module
6+
import pkg_resources
7+
import pytest
138
from _pytest.doctest import DoctestItem
9+
from _pytest.main import Session
1410
from _pytest.nodes import File, Item
11+
from _pytest.python import Class, Function, Instance, Module
1512
from _pytest.unittest import TestCaseFunction, UnitTestCase
1613
from reportportal_client import ReportPortalServiceAsync
14+
from six import with_metaclass
15+
from six.moves import queue
1716

1817
log = logging.getLogger(__name__)
1918

@@ -92,10 +91,13 @@ def init_service(self, endpoint, project, uuid, log_batch_size,
9291
project=project,
9392
token=uuid,
9493
error_handler=self.async_error_handler,
95-
log_batch_size=log_batch_size,
96-
verify_ssl=verify_ssl
94+
log_batch_size=log_batch_size # ,
95+
# verify_ssl=verify_ssl
9796
)
98-
self.project_settiings = self.RP.rp_client.get_project_settings() if self.RP else None
97+
if self.RP and hasattr(self.RP.rp_client, "get_project_settings"):
98+
self.project_settiings = self.RP.rp_client.get_project_settings()
99+
else:
100+
self.project_settiings = None
99101
self.issue_types = self.get_issue_types()
100102
else:
101103
log.debug('The pytest is already initialized')
@@ -130,7 +132,6 @@ def start_launch(self, launch_name,
130132
req_data = self.RP.start_launch(**sl_pt)
131133
log.debug('ReportPortal - Launch started: response_body=%s', req_data)
132134

133-
134135
def collect_tests(self, session):
135136
self._stop_if_necessary()
136137
if self.RP is None:
@@ -140,12 +141,14 @@ def collect_tests(self, session):
140141
hier_module = False
141142
hier_class = False
142143
hier_param = False
144+
display_suite_file_name = True
143145

144146
if not hasattr(session.config, 'slaveinput'):
145147
hier_dirs = session.config.getini('rp_hierarchy_dirs')
146148
hier_module = session.config.getini('rp_hierarchy_module')
147149
hier_class = session.config.getini('rp_hierarchy_class')
148150
hier_param = session.config.getini('rp_hierarchy_parametrize')
151+
display_suite_file_name = session.config.getini('rp_display_suite_test_file')
149152

150153
try:
151154
hier_dirs_level = int(session.config.getini('rp_hierarchy_dirs_level'))
@@ -181,6 +184,8 @@ def collect_tests(self, session):
181184

182185
self._item_parts[item] = parts
183186
for part in parts:
187+
if '_pytest.python.Class' in str(type(part)) and not display_suite_file_name and not hier_module:
188+
part._rp_name = part._rp_name.split("::")[-1]
184189
if part not in self._hier_parts:
185190
self._hier_parts[part] = {"finish_counter": 1, "start_flag": False}
186191
else:
@@ -249,7 +254,6 @@ def finish_pytest_item(self, test_item, status, issue=None):
249254
log.debug('ReportPortal - End TestSuite: request_body=%s', payload)
250255
self.RP.finish_test_item(**payload)
251256

252-
253257
def finish_launch(self, launch=None, status='rp_launch'):
254258
self._stop_if_necessary()
255259
if self.RP is None:
@@ -347,7 +351,8 @@ def _add_item_hier_parts_parametrize(item, report_parts, tests_parts, rp_name=""
347351
if test_fullname in tests_parts:
348352
item_test = tests_parts[test_fullname]
349353
else:
350-
item_test = Item(test_fullname, nodeid=test_fullname, session=item.session, config=item.session.config)
354+
item_test = Item(test_fullname, nodeid=test_fullname, session=item.session,
355+
config=item.session.config)
351356
item_test._rp_name = rp_name
352357
item_test.obj = item.obj
353358
item_test.keywords = item.keywords

0 commit comments

Comments
 (0)