diff --git a/pytest_reportportal/service.py b/pytest_reportportal/service.py index fceb5f44..75fa80e0 100644 --- a/pytest_reportportal/service.py +++ b/pytest_reportportal/service.py @@ -457,12 +457,31 @@ def _merge_leaf_types(self, test_tree: dict[str, Any], leaf_types: set, separato self._merge_leaf_types(child_leaf, leaf_types, separator) def _merge_dirs(self, test_tree: dict[str, Any]) -> None: + """Merge directory and file leaves using configured separator. + + :param test_tree: Test tree structure to merge + """ self._merge_leaf_types(test_tree, {LeafType.DIR, LeafType.FILE}, self._config.rp_dir_path_separator) - def _merge_code_with_separator(self, test_tree: dict[str, Any], separator: str) -> None: - self._merge_leaf_types(test_tree, {LeafType.CODE, LeafType.FILE, LeafType.DIR, LeafType.SUITE}, separator) + def _merge_code_with_separator(self, test_tree: dict[str, Any], separator: str, is_bdd: bool = False) -> None: + """Merge code and suite leaves, respecting hierarchy flags. + + :param test_tree: Test tree structure to merge + :param separator: Separator to use when merging names + :param is_bdd: If True, always merge FILE for BDD scenarios. Otherwise respect rp_hierarchy_test_file + """ + types_to_merge = {LeafType.CODE, LeafType.SUITE} + if is_bdd or not self._config.rp_hierarchy_test_file: + types_to_merge.add(LeafType.FILE) + if not self._config.rp_hierarchy_dirs: + types_to_merge.add(LeafType.DIR) + self._merge_leaf_types(test_tree, types_to_merge, separator) def _merge_code(self, test_tree: dict[str, Any]) -> None: + """Merge code and suite leaves using double colon separator. + + :param test_tree: Test tree structure to merge + """ self._merge_code_with_separator(test_tree, "::") def _build_item_paths(self, leaf: dict[str, Any], path: list[dict[str, Any]]) -> None: @@ -1185,7 +1204,7 @@ def start_bdd_scenario(self, feature: Feature, scenario: Scenario) -> None: self._generate_names(root_leaf) if not self._config.rp_hierarchy_code: try: - self._merge_code_with_separator(root_leaf, " - ") + self._merge_code_with_separator(root_leaf, " - ", is_bdd=True) except Exception as e: LOGGER.exception(e) self._build_item_paths(root_leaf, []) diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index d57be797..3d59848e 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -35,6 +35,7 @@ + [["examples/hierarchy/inner/test_inner_simple.py"]] * 7 + [["examples/hierarchy/test_in_class_in_class.py"]] + [["examples/test_simple.py"]] * 2 + + [["examples/hierarchy/inner/test_inner_simple.py"]] ) # noinspection PyTypeChecker @@ -65,6 +66,10 @@ dict(**utils.DEFAULT_VARIABLES), dict({"rp_hierarchy_test_file": False}, **utils.DEFAULT_VARIABLES), dict({"rp_hierarchy_test_file": False, "rp_hierarchy_dirs_level": 1}, **utils.DEFAULT_VARIABLES), + dict( + {"rp_hierarchy_dirs": True, "rp_hierarchy_test_file": True, "rp_hierarchy_code": False}, + **utils.DEFAULT_VARIABLES, + ), ] HIERARCHY_TEST_EXPECTED_ITEMS = [ @@ -271,6 +276,13 @@ ], [{"name": "examples::test_simple", "item_type": "STEP", "parent_item_id": lambda x: x is None}], [{"name": "test_simple", "item_type": "STEP", "parent_item_id": lambda x: x is None}], + [ + {"name": "examples", "item_type": "SUITE", "parent_item_id": lambda x: x is None}, + {"name": "hierarchy", "item_type": "SUITE", "parent_item_id": lambda x: x.startswith("examples")}, + {"name": "inner", "item_type": "SUITE", "parent_item_id": lambda x: x.startswith("hierarchy")}, + {"name": "test_inner_simple.py", "item_type": "SUITE", "parent_item_id": lambda x: x.startswith("inner")}, + {"name": "test_simple", "item_type": "STEP", "parent_item_id": lambda x: x.startswith("test_inner_simple.py")}, + ], ] HIERARCHY_TEST_PARAMETERS = [