Skip to content

Commit ea3e87c

Browse files
authored
Merge pull request #383 from ramir-dn/restore_rp_display_suite_test_file
Restore rp_display_suite_test_file and fix bug with rp_dir_level
2 parents 1bcb242 + 7b6cec8 commit ea3e87c

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-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
@@ -100,6 +100,7 @@ class LeafType(Enum):
100100
"""This class stores test item path types."""
101101

102102
DIR = auto()
103+
FILE = auto()
103104
CODE = auto()
104105
ROOT = auto()
105106

@@ -272,28 +273,37 @@ def _build_test_tree(self, session: Session) -> Dict[str, Any]:
272273
children_leafs = current_leaf['children']
273274

274275
leaf_type = LeafType.DIR
275-
if i >= len(dir_path):
276+
if i == len(dir_path):
277+
leaf_type = LeafType.FILE
278+
if i > len(dir_path):
276279
leaf_type = LeafType.CODE
277280

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

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

298308
def _generate_names(self, test_tree: Dict[str, Any]) -> None:
299309
if test_tree['type'] == LeafType.ROOT:
@@ -302,7 +312,7 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
302312
if test_tree['type'] == LeafType.DIR:
303313
test_tree['name'] = test_tree['item'].basename
304314

305-
if test_tree['type'] == LeafType.CODE:
315+
if test_tree['type'] in [LeafType.CODE, LeafType.FILE]:
306316
item = test_tree['item']
307317
if isinstance(item, Module):
308318
test_tree['name'] = os.path.split(str(item.fspath))[1]
@@ -312,11 +322,11 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
312322
for item, child_leaf in test_tree['children'].items():
313323
self._generate_names(child_leaf)
314324

315-
def _merge_leaf_type(self, test_tree, leaf_type, separator):
325+
def _merge_leaf_types(self, test_tree, leaf_types, separator):
316326
child_items = list(test_tree['children'].items())
317-
if test_tree['type'] != leaf_type:
327+
if test_tree['type'] not in leaf_types:
318328
for item, child_leaf in child_items:
319-
self._merge_leaf_type(child_leaf, leaf_type, separator)
329+
self._merge_leaf_types(child_leaf, leaf_types, separator)
320330
elif len(test_tree['children'].items()) > 0:
321331
parent_leaf = test_tree['parent']
322332
current_item = test_tree['item']
@@ -327,13 +337,13 @@ def _merge_leaf_type(self, test_tree, leaf_type, separator):
327337
child_leaf['parent'] = parent_leaf
328338
child_leaf['name'] = \
329339
current_name + separator + child_leaf['name']
330-
self._merge_leaf_type(child_leaf, leaf_type, separator)
340+
self._merge_leaf_types(child_leaf, leaf_types, separator)
331341

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

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

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

tests/unit/test_plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def test_pytest_addoption_adds_correct_ini_file_arguments():
353353
'rp_hierarchy_code',
354354
'rp_hierarchy_dirs_level',
355355
'rp_hierarchy_dirs',
356+
'rp_display_suite_test_file',
356357
'rp_hierarchy_dir_path_separator',
357358
'rp_issue_system_url',
358359
'rp_bts_issue_url',

0 commit comments

Comments
 (0)