Skip to content

Commit f857b52

Browse files
bigbZikYury Krasouski
authored andcommitted
- Adding new pytest ini option 'rp_tests_tags', to add tags for each items in the launch (#81)
- Removing docstring indentations for item description (see https://www.python.org/dev/peps/pep-0257/)
1 parent 0acf697 commit f857b52

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ The following parameters are optional:
5555

5656
- :code:`rp_launch = AnyLaunchName` - launch name (could be overridden
5757
by pytest --rp-launch option, default value is 'Pytest Launch')
58-
- :code:`rp_launch_tags = 'PyTest' 'Smoke'` - list of tags
58+
- :code:`rp_launch_tags = 'PyTest' 'Smoke'` - list of tags for launch
59+
- :code:`rp_tests_tags = 'PyTest' 'Smoke'` - list of tags that will be added for each item in the launch
5960
- :code:`rp_launch_description = 'Smoke test'` - launch description (could be overridden
6061
by pytest --rp-launch-description option, default value is '')
6162

pytest_reportportal/plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ def pytest_addoption(parser):
226226
type='args',
227227
help='Launch tags, i.e Performance Regression')
228228

229+
parser.addini(
230+
'rp_tests_tags',
231+
type='args',
232+
help='Tags for all tests items, e.g. Smoke')
233+
229234
parser.addini(
230235
'rp_launch_description',
231236
default='',

pytest_reportportal/service.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ def timestamp():
2121
return str(int(time() * 1000))
2222

2323

24+
def trim_docstring(docstring):
25+
if not docstring:
26+
return ''
27+
# Convert tabs to spaces (following the normal Python rules)
28+
# and split into a list of lines:
29+
lines = docstring.expandtabs().splitlines()
30+
# Determine minimum indentation (first line doesn't count):
31+
indent = sys.maxsize
32+
for line in lines[1:]:
33+
stripped = line.lstrip()
34+
if stripped:
35+
indent = min(indent, len(line) - len(stripped))
36+
# Remove indentation (first line is special):
37+
trimmed = [lines[0].strip()]
38+
if indent < sys.maxsize:
39+
for line in lines[1:]:
40+
trimmed.append(line[indent:].rstrip())
41+
# Strip off trailing and leading blank lines:
42+
while trimmed and not trimmed[-1]:
43+
trimmed.pop()
44+
while trimmed and not trimmed[0]:
45+
trimmed.pop(0)
46+
# Return a single string:
47+
return '\n'.join(trimmed)
48+
49+
2450
class Singleton(type):
2551
_instances = {}
2652

@@ -385,8 +411,13 @@ def _get_item_dirs(item):
385411
def _get_item_tags(self, item):
386412
# Try to extract names of @pytest.mark.* decorators used for test item
387413
# and exclude those which present in rp_ignore_tags parameter
388-
return [k for k in item.keywords if item.get_marker(k) is not None
414+
#return [k for k in item.keywords if item.get_marker(k) is not None
415+
# and k not in self.ignored_tags]
416+
tags = [k for k in item.keywords if item.get_marker(k) is not None
389417
and k not in self.ignored_tags]
418+
tags.extend(item.session.config.getini('rp_tests_tags'))
419+
420+
return tags
390421

391422
def _get_parameters(self, item):
392423
return item.callspec.params if hasattr(item, 'callspec') else {}
@@ -408,6 +439,6 @@ def _get_item_description(test_item):
408439
if isinstance(test_item, (Class, Function, Module, Item)):
409440
doc = test_item.obj.__doc__
410441
if doc is not None:
411-
return doc.strip()
442+
return trim_docstring(doc)
412443
if isinstance(test_item, DoctestItem):
413444
return test_item.reportinfo()[2]

0 commit comments

Comments
 (0)