Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions pytest_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +473 to +478
Comment thread
coderabbitai[bot] marked this conversation as resolved.

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:
Expand Down Expand Up @@ -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, [])
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down