Skip to content

Commit 831efb7

Browse files
author
Dzmitry Humianiuk
authored
Merge branch 'master' into patch-1
2 parents 3c64853 + c4a5d85 commit 831efb7

File tree

7 files changed

+264
-701
lines changed

7 files changed

+264
-701
lines changed

LICENSE

Lines changed: 201 additions & 674 deletions
Large diffs are not rendered by default.

README.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ agent-python-pytest
77

88
Pytest plugin for reporting test results of Pytest to the 'Reportal Portal'.
99

10+
* Usage
11+
* Configuration
12+
* Examples
13+
* Launching
14+
* Send attachement (screenshots)
15+
* Troubleshooting
16+
* Copyright Notice
17+
1018
Usage
1119
-----
1220

@@ -69,8 +77,10 @@ The following parameters are optional:
6977
- :code:`rp_hierarchy_parametrize = True` - Enables hierarchy parametrized tests, default `False`. Doesn't support 'xdist' plugin.
7078
- :code:`rp_hierarchy_dirs_level = 0` - Directory starting hierarchy level (from pytest.ini level) (default `0`)
7179
- :code:`rp_issue_marks = 'xfail' 'issue'` - Pytest marks that could be used to get issue information (id, type, reason)
72-
- :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)
7381
- :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+
7484

7585
If you like to override the above parameters from command line, or from CI environment based on your build, then pass
7686
- :code:`-o "rp_launch_tags=Smoke Tests"` during invocation.
@@ -181,6 +191,13 @@ Example:
181191
assert False
182192
183193
194+
Send attachement (screenshots)
195+
----------------
196+
197+
https://github.com/reportportal/client-Python#send-attachement-screenshots
198+
199+
200+
184201
Troubleshooting
185202
~~~~~~~~~
186203

@@ -205,9 +222,12 @@ deactivate :code:`pytest_reportportal` plugin with command like:
205222
py.test -p no:pytest_reportportal ./tests
206223
207224
225+
208226
Copyright Notice
209227
----------------
228+
.. Copyright Notice: https://github.com/reportportal/agent-python-pytest#copyright-notice
210229
211230
Licensed under the GPLv3_ license (see the LICENSE file).
212231

213232
.. _GPLv3: https://www.gnu.org/licenses/quick-guide-gplv3.html
233+

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/rp_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ def makeRecord(self, name, level, fn, lno, msg, args, exc_info,
142142
return record
143143
return makeRecord
144144

145-
if not logger_class == RPLogger:
145+
if not logger_class == RPLogger and not hasattr(logger_class, "_patched"):
146146
logger_class._log = wrap_log(logger_class._log)
147147
logger_class.makeRecord = wrap_makeRecord(logger_class.makeRecord)
148-
148+
logger_class._patched = True
149149
yield
150150

151151
finally:

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

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def read_file(fname):
88
return f.read()
99

1010

11-
version = '1.0.4'
11+
version = '1.0.5'
1212
tar_url = 'https://github.com/reportportal/agent-python-pytest/tarball/1.0.3'
1313

1414

@@ -25,13 +25,14 @@ 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',
3132
download_url=tar_url,
3233
packages=['pytest_reportportal'],
3334
install_requires=requirements,
34-
license='GNU General Public License v3',
35+
license='Apache 2.0',
3536
keywords=['testing', 'reporting', 'reportportal', 'pytest'],
3637
classifiers=[
3738
'Framework :: Pytest',

0 commit comments

Comments
 (0)