Skip to content

Commit 13810cb

Browse files
committed
Merged with master
2 parents 97d6281 + c4a5d85 commit 13810cb

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
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
@@ -299,6 +299,14 @@ def pytest_addoption(parser):
299299
type='bool',
300300
help='Verify HTTPS calls')
301301

302+
parser.addini(
303+
'rp_display_suite_test_file',
304+
default=True,
305+
type='bool',
306+
help="In case of True, include the suite's relative file path in the launch name as a convention of "
307+
"'<RELATIVE_FILE_PATH>::<SUITE_NAME>'. In case of False, set the launch name to be the suite name "
308+
"only - this flag is relevant only when 'rp_hierarchy_module' flag is set to False")
309+
302310
parser.addini(
303311
'retries',
304312
default='0',

pytest_reportportal/service.py

Lines changed: 19 additions & 14 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

@@ -93,11 +92,14 @@ def init_service(self, endpoint, project, uuid, log_batch_size,
9392
project=project,
9493
token=uuid,
9594
error_handler=self.async_error_handler,
96-
log_batch_size=log_batch_size,
97-
verify_ssl=verify_ssl,
98-
retries=retries
95+
retries=retries,
96+
log_batch_size=log_batch_size # ,
97+
# verify_ssl=verify_ssl
9998
)
100-
self.project_settiings = self.RP.rp_client.get_project_settings() if self.RP else None
99+
if self.RP and hasattr(self.RP.rp_client, "get_project_settings"):
100+
self.project_settiings = self.RP.rp_client.get_project_settings()
101+
else:
102+
self.project_settiings = None
101103
self.issue_types = self.get_issue_types()
102104
else:
103105
log.debug('The pytest is already initialized')
@@ -132,7 +134,6 @@ def start_launch(self, launch_name,
132134
req_data = self.RP.start_launch(**sl_pt)
133135
log.debug('ReportPortal - Launch started: response_body=%s', req_data)
134136

135-
136137
def collect_tests(self, session):
137138
self._stop_if_necessary()
138139
if self.RP is None:
@@ -142,12 +143,14 @@ def collect_tests(self, session):
142143
hier_module = False
143144
hier_class = False
144145
hier_param = False
146+
display_suite_file_name = True
145147

146148
if not hasattr(session.config, 'slaveinput'):
147149
hier_dirs = session.config.getini('rp_hierarchy_dirs')
148150
hier_module = session.config.getini('rp_hierarchy_module')
149151
hier_class = session.config.getini('rp_hierarchy_class')
150152
hier_param = session.config.getini('rp_hierarchy_parametrize')
153+
display_suite_file_name = session.config.getini('rp_display_suite_test_file')
151154

152155
try:
153156
hier_dirs_level = int(session.config.getini('rp_hierarchy_dirs_level'))
@@ -183,6 +186,8 @@ def collect_tests(self, session):
183186

184187
self._item_parts[item] = parts
185188
for part in parts:
189+
if '_pytest.python.Class' in str(type(part)) and not display_suite_file_name and not hier_module:
190+
part._rp_name = part._rp_name.split("::")[-1]
186191
if part not in self._hier_parts:
187192
self._hier_parts[part] = {"finish_counter": 1, "start_flag": False}
188193
else:
@@ -251,7 +256,6 @@ def finish_pytest_item(self, test_item, status, issue=None):
251256
log.debug('ReportPortal - End TestSuite: request_body=%s', payload)
252257
self.RP.finish_test_item(**payload)
253258

254-
255259
def finish_launch(self, launch=None, status='rp_launch'):
256260
self._stop_if_necessary()
257261
if self.RP is None:
@@ -349,7 +353,8 @@ def _add_item_hier_parts_parametrize(item, report_parts, tests_parts, rp_name=""
349353
if test_fullname in tests_parts:
350354
item_test = tests_parts[test_fullname]
351355
else:
352-
item_test = Item(test_fullname, nodeid=test_fullname, session=item.session, config=item.session.config)
356+
item_test = Item(test_fullname, nodeid=test_fullname, session=item.session,
357+
config=item.session.config)
353358
item_test._rp_name = rp_name
354359
item_test.obj = item.obj
355360
item_test.keywords = item.keywords

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def read_file(fname):
2525
version=version,
2626
description='Agent for Reporting results of tests to the Report Portal',
2727
long_description=read_file('README.rst'),
28+
long_description_content_type='text/markdown',
2829
author='Pavel Papou',
2930
author_email='[email protected]',
3031
url='https://github.com/reportportal/agent-python-pytest',

0 commit comments

Comments
 (0)