@@ -241,7 +241,7 @@ def _get_tree_path(self, item: Item) -> List[Item]:
241241 path .reverse ()
242242 return path
243243
244- def _get_leaf (self , leaf_type : LeafType , parent_item : Optional [Dict [str , Any ]], item : Optional [Item ],
244+ def _get_leaf (self , leaf_type , parent_item : Optional [Dict [str , Any ]], item : Optional [Item ],
245245 item_id : Optional [str ] = None ) -> Dict [str , Any ]:
246246 """Construct a leaf for the itest tree.
247247
@@ -283,27 +283,36 @@ def _build_test_tree(self, session: Session) -> Dict[str, Any]:
283283 current_leaf = children_leafs [leaf ]
284284 return test_tree
285285
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-
296- def _remove_root_dirs (self , test_tree : Dict [str , Any ], max_dir_level , dir_level = 0 ) -> None :
286+ def _remove_root_dirs (self , test_tree : Dict [str , Any ], max_dir_level : int , dir_level : int = 0 ) -> None :
297287 if test_tree ['type' ] == LeafType .ROOT :
298- for child_leaf in list (test_tree ['children' ].values ()):
288+ items = list (test_tree ['children' ].items ())
289+ for item , child_leaf in items :
299290 self ._remove_root_dirs (child_leaf , max_dir_level , 1 )
300291 return
301292 if test_tree ['type' ] == LeafType .DIR and dir_level <= max_dir_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 )
293+ new_level = dir_level + 1
294+ parent_leaf = test_tree ['parent' ]
295+ current_item = test_tree ['item' ]
296+ del parent_leaf ['children' ][current_item ]
297+ for item , child_leaf in test_tree ['children' ].items ():
298+ parent_leaf ['children' ][item ] = child_leaf
299+ child_leaf ['parent' ] = parent_leaf
300+ self ._remove_root_dirs (child_leaf , max_dir_level , new_level )
301+
302+ def _remove_file_names (self , test_tree : Dict [str , Any ]) -> None :
303+ if test_tree ['type' ] != LeafType .FILE :
304+ items = list (test_tree ['children' ].items ())
305+ for item , child_leaf in items :
306+ self ._remove_file_names (child_leaf )
306307 return
308+ if not self ._config .rp_hierarchy_test_file :
309+ parent_leaf = test_tree ['parent' ]
310+ current_item = test_tree ['item' ]
311+ del parent_leaf ['children' ][current_item ]
312+ for item , child_leaf in test_tree ['children' ].items ():
313+ parent_leaf ['children' ][item ] = child_leaf
314+ child_leaf ['parent' ] = parent_leaf
315+ self ._remove_file_names (child_leaf )
307316
308317 def _generate_names (self , test_tree : Dict [str , Any ]) -> None :
309318 if test_tree ['type' ] == LeafType .ROOT :
@@ -312,7 +321,7 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
312321 if test_tree ['type' ] == LeafType .DIR :
313322 test_tree ['name' ] = test_tree ['item' ].basename
314323
315- if test_tree ['type' ] in [ LeafType .CODE , LeafType .FILE ] :
324+ if test_tree ['type' ] in { LeafType .CODE , LeafType .FILE } :
316325 item = test_tree ['item' ]
317326 if isinstance (item , Module ):
318327 test_tree ['name' ] = os .path .split (str (item .fspath ))[1 ]
@@ -322,7 +331,7 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
322331 for item , child_leaf in test_tree ['children' ].items ():
323332 self ._generate_names (child_leaf )
324333
325- def _merge_leaf_types (self , test_tree , leaf_types , separator ):
334+ def _merge_leaf_types (self , test_tree : Dict [ str , Any ], leaf_types : Set , separator : str ):
326335 child_items = list (test_tree ['children' ].items ())
327336 if test_tree ['type' ] not in leaf_types :
328337 for item , child_leaf in child_items :
@@ -335,15 +344,14 @@ def _merge_leaf_types(self, test_tree, leaf_types, separator):
335344 for item , child_leaf in child_items :
336345 parent_leaf ['children' ][item ] = child_leaf
337346 child_leaf ['parent' ] = parent_leaf
338- child_leaf ['name' ] = \
339- current_name + separator + child_leaf ['name' ]
347+ child_leaf ['name' ] = current_name + separator + child_leaf ['name' ]
340348 self ._merge_leaf_types (child_leaf , leaf_types , separator )
341349
342350 def _merge_dirs (self , test_tree : Dict [str , Any ]) -> None :
343- self ._merge_leaf_types (test_tree , [ LeafType .DIR ] , self ._config .rp_dir_path_separator )
351+ self ._merge_leaf_types (test_tree , { LeafType .DIR } , self ._config .rp_dir_path_separator )
344352
345353 def _merge_code (self , test_tree : Dict [str , Any ]) -> None :
346- self ._merge_leaf_types (test_tree , [ LeafType .CODE , LeafType .FILE ] , '::' )
354+ self ._merge_leaf_types (test_tree , { LeafType .CODE , LeafType .FILE } , '::' )
347355
348356 def _build_item_paths (self , leaf : Dict [str , Any ], path : List [Dict [str , Any ]]) -> None :
349357 if 'children' in leaf and len (leaf ['children' ]) > 0 :
@@ -363,6 +371,7 @@ def collect_tests(self, session: Session) -> None:
363371 # Create a test tree to be able to apply mutations
364372 test_tree = self ._build_test_tree (session )
365373 self ._remove_root_dirs (test_tree , self ._config .rp_dir_level )
374+ self ._remove_file_names (test_tree )
366375 self ._generate_names (test_tree )
367376 if not self ._config .rp_hierarchy_dirs :
368377 self ._merge_dirs (test_tree )
0 commit comments