Skip to content

Commit e9b3bea

Browse files
committed
Restore rp_display_suite_test_file and fix bug with rp_dir_level
1 parent 416335a commit e9b3bea

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

pytest_reportportal/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class AgentConfig:
4040
rp_hierarchy_code: bool
4141
rp_dir_level: int
4242
rp_hierarchy_dirs: bool
43+
rp_display_suite_test_file: bool
4344
rp_dir_path_separator: str
4445
rp_ignore_attributes: set
4546
rp_is_skipped_an_issue: bool
@@ -80,6 +81,8 @@ def __init__(self, pytest_config: Config) -> None:
8081
'rp_hierarchy_dirs_level'))
8182
self.rp_hierarchy_dirs = self.find_option(pytest_config,
8283
'rp_hierarchy_dirs')
84+
self.rp_display_suite_test_file = self.find_option(pytest_config,
85+
'rp_display_suite_test_file')
8386
self.rp_dir_path_separator = \
8487
self.find_option(pytest_config, 'rp_hierarchy_dir_path_separator')
8588
self.rp_ignore_attributes = set(self.find_option(pytest_config, 'rp_ignore_attributes') or [])

pytest_reportportal/plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,11 @@ def add_shared_option(name, help_str, default=None, action='store'):
501501
default=False,
502502
type='bool',
503503
help='Enables hierarchy for directories')
504+
parser.addini(
505+
'rp_display_suite_test_file',
506+
default=True,
507+
type='bool',
508+
help='Show file name in hierarchy. Depends on rp_hierarchy_dirs_level to get deep enough')
504509
parser.addini(
505510
'rp_hierarchy_dir_path_separator',
506511
default=os.path.sep,

pytest_reportportal/service.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class LeafType(Enum):
9999
"""This class stores test item path types."""
100100

101101
DIR = auto()
102+
FILE = auto()
102103
CODE = auto()
103104
ROOT = auto()
104105

@@ -270,28 +271,37 @@ def _build_test_tree(self, session: Session) -> Dict[str, Any]:
270271
children_leafs = current_leaf['children']
271272

272273
leaf_type = LeafType.DIR
273-
if i >= len(dir_path):
274+
if i == len(dir_path):
275+
leaf_type = LeafType.FILE
276+
if i > len(dir_path):
274277
leaf_type = LeafType.CODE
275278

276279
if leaf not in children_leafs:
277280
children_leafs[leaf] = self._get_leaf(leaf_type, current_leaf, leaf)
278281
current_leaf = children_leafs[leaf]
279282
return test_tree
280283

284+
def _remove_node(self, test_tree: Dict[str, Any], max_dir_level, dir_level, recursive):
285+
parent_leaf = test_tree['parent']
286+
current_item = test_tree['item']
287+
del parent_leaf['children'][current_item]
288+
for item, child_leaf in test_tree['children'].items():
289+
parent_leaf['children'][item] = child_leaf
290+
child_leaf['parent'] = parent_leaf
291+
if recursive:
292+
self._remove_root_dirs(child_leaf, max_dir_level, dir_level + 1)
293+
281294
def _remove_root_dirs(self, test_tree: Dict[str, Any], max_dir_level, dir_level=0) -> None:
282295
if test_tree['type'] == LeafType.ROOT:
283-
for item, child_leaf in test_tree['children'].items():
296+
for child_leaf in list(test_tree['children'].values()):
284297
self._remove_root_dirs(child_leaf, max_dir_level, 1)
285-
return
298+
return
286299
if test_tree['type'] == LeafType.DIR and dir_level <= max_dir_level:
287-
new_level = dir_level + 1
288-
parent_leaf = test_tree['parent']
289-
current_item = test_tree['item']
290-
del parent_leaf['children'][current_item]
291-
for item, child_leaf in test_tree['children'].items():
292-
parent_leaf['children'][item] = child_leaf
293-
child_leaf['parent'] = parent_leaf
294-
self._remove_root_dirs(child_leaf, max_dir_level, new_level)
300+
self._remove_node(test_tree, max_dir_level, dir_level, recursive=True)
301+
return
302+
if test_tree['type'] == LeafType.FILE and not self._config.rp_display_suite_test_file:
303+
self._remove_node(test_tree, max_dir_level, dir_level, recursive=False)
304+
return
295305

296306
def _generate_names(self, test_tree: Dict[str, Any]) -> None:
297307
if test_tree['type'] == LeafType.ROOT:
@@ -300,7 +310,7 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
300310
if test_tree['type'] == LeafType.DIR:
301311
test_tree['name'] = test_tree['item'].basename
302312

303-
if test_tree['type'] == LeafType.CODE:
313+
if test_tree['type'] in [LeafType.CODE, LeafType.FILE]:
304314
item = test_tree['item']
305315
if isinstance(item, Module):
306316
test_tree['name'] = os.path.split(str(item.fspath))[1]
@@ -310,11 +320,11 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
310320
for item, child_leaf in test_tree['children'].items():
311321
self._generate_names(child_leaf)
312322

313-
def _merge_leaf_type(self, test_tree, leaf_type, separator):
323+
def _merge_leaf_types(self, test_tree, leaf_types, separator):
314324
child_items = list(test_tree['children'].items())
315-
if test_tree['type'] != leaf_type:
325+
if test_tree['type'] not in leaf_types:
316326
for item, child_leaf in child_items:
317-
self._merge_leaf_type(child_leaf, leaf_type, separator)
327+
self._merge_leaf_types(child_leaf, leaf_types, separator)
318328
elif len(test_tree['children'].items()) > 0:
319329
parent_leaf = test_tree['parent']
320330
current_item = test_tree['item']
@@ -325,13 +335,13 @@ def _merge_leaf_type(self, test_tree, leaf_type, separator):
325335
child_leaf['parent'] = parent_leaf
326336
child_leaf['name'] = \
327337
current_name + separator + child_leaf['name']
328-
self._merge_leaf_type(child_leaf, leaf_type, separator)
338+
self._merge_leaf_types(child_leaf, leaf_types, separator)
329339

330340
def _merge_dirs(self, test_tree: Dict[str, Any]) -> None:
331-
self._merge_leaf_type(test_tree, LeafType.DIR, self._config.rp_dir_path_separator)
341+
self._merge_leaf_types(test_tree, [LeafType.DIR], self._config.rp_dir_path_separator)
332342

333343
def _merge_code(self, test_tree: Dict[str, Any]) -> None:
334-
self._merge_leaf_type(test_tree, LeafType.CODE, '::')
344+
self._merge_leaf_types(test_tree, [LeafType.CODE, LeafType.FILE], '::')
335345

336346
def _build_item_paths(self, leaf: Dict[str, Any], path: List[Dict[str, Any]]) -> None:
337347
if 'children' in leaf and len(leaf['children']) > 0:

0 commit comments

Comments
 (0)