6767 make_python_name : Callable [[str ], str ] = lambda x : x
6868 PYTEST_BDD = False
6969
70+ try :
71+ # noinspection PyPackageRequirements
72+ from pytest_bdd .parser import Rule
73+ except ImportError :
74+ Rule = type ("dummy" , (), {}) # Old pytest-bdd versions do not have Rule
75+
7076from reportportal_client import RP , create_client
7177from reportportal_client .helpers import dict_to_payload , gen_attributes , get_launch_sys_attrs , get_package_version
7278
@@ -366,9 +372,18 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
366372 elif isinstance (item , Scenario ):
367373 keyword = getattr (item , "keyword" , "Scenario" )
368374 test_tree ["name" ] = f"{ keyword } : { item .name } "
375+ elif isinstance (item , Rule ):
376+ keyword = getattr (item , "keyword" , "Rule" )
377+ test_tree ["name" ] = f"{ keyword } : { item .name } "
369378 else :
370379 test_tree ["name" ] = item .name
371380
381+ if test_tree ["type" ] == LeafType .SUITE :
382+ item = test_tree ["item" ]
383+ if isinstance (item , Rule ):
384+ keyword = getattr (item , "keyword" , "Rule" )
385+ test_tree ["name" ] = f"{ keyword } : { item .name } "
386+
372387 for item , child_leaf in test_tree ["children" ].items ():
373388 self ._generate_names (child_leaf )
374389
@@ -395,7 +410,7 @@ def _merge_dirs(self, test_tree: Dict[str, Any]) -> None:
395410 self ._merge_leaf_types (test_tree , {LeafType .DIR , LeafType .FILE }, self ._config .rp_dir_path_separator )
396411
397412 def _merge_code_with_separator (self , test_tree : Dict [str , Any ], separator : str ) -> None :
398- self ._merge_leaf_types (test_tree , {LeafType .CODE , LeafType .FILE , LeafType .DIR }, separator )
413+ self ._merge_leaf_types (test_tree , {LeafType .CODE , LeafType .FILE , LeafType .DIR , LeafType . SUITE }, separator )
399414
400415 def _merge_code (self , test_tree : Dict [str , Any ]) -> None :
401416 self ._merge_code_with_separator (test_tree , "::" )
@@ -454,7 +469,7 @@ def _get_item_description(self, test_item: Any) -> Optional[str]:
454469 return trim_docstring (doc )
455470 if isinstance (test_item , DoctestItem ):
456471 return test_item .reportinfo ()[2 ]
457- if isinstance (test_item , (Feature , Scenario , ScenarioTemplate )):
472+ if isinstance (test_item , (Feature , Scenario , ScenarioTemplate , Rule )):
458473 description = test_item .description
459474 if description :
460475 return description
@@ -472,7 +487,7 @@ def _lock(self, leaf: Dict[str, Any], func: Callable[[Dict[str, Any]], Any]) ->
472487 return func (leaf )
473488 return func (leaf )
474489
475- def _process_bdd_attributes (self , scenario : Union [Feature , Scenario ]) -> List [Dict [str , str ]]:
490+ def _process_bdd_attributes (self , scenario : Union [Feature , Scenario , Rule ]) -> List [Dict [str , str ]]:
476491 attributes = []
477492 for tag in scenario .tags :
478493 key = None
@@ -485,7 +500,7 @@ def _process_bdd_attributes(self, scenario: Union[Feature, Scenario]) -> List[Di
485500 attributes .append (attribute )
486501 return attributes
487502
488- def _build_start_suite_rq (self , leaf : Dict [str , Any ]) -> Dict [ str , Any ] :
503+ def _get_suite_code_ref (self , leaf : Dict [str , Any ]) -> str :
489504 item = leaf ["item" ]
490505 if leaf ["type" ] == LeafType .DIR :
491506 code_ref = str (item )
@@ -494,9 +509,16 @@ def _build_start_suite_rq(self, leaf: Dict[str, Any]) -> Dict[str, Any]:
494509 code_ref = str (item .rel_filename )
495510 else :
496511 code_ref = str (item .fspath )
512+ elif leaf ["type" ] == LeafType .SUITE :
513+ code_ref = self ._get_suite_code_ref (leaf ["parent" ]) + f"/[{ type (item ).__name__ } :{ item .name } ]"
497514 else :
498515 code_ref = str (item .fspath )
516+ return code_ref
517+
518+ def _build_start_suite_rq (self , leaf : Dict [str , Any ]) -> Dict [str , Any ]:
519+ code_ref = self ._get_suite_code_ref (leaf )
499520 parent_item_id = self ._lock (leaf ["parent" ], lambda p : p .get ("item_id" )) if "parent" in leaf else None
521+ item = leaf ["item" ]
500522 payload = {
501523 "name" : self ._truncate_item_name (leaf ["name" ]),
502524 "description" : self ._get_item_description (item ),
@@ -505,7 +527,7 @@ def _build_start_suite_rq(self, leaf: Dict[str, Any]) -> Dict[str, Any]:
505527 "code_ref" : code_ref ,
506528 "parent_item_id" : parent_item_id ,
507529 }
508- if isinstance (item , Feature ):
530+ if isinstance (item , ( Feature , Scenario , Rule ) ):
509531 payload ["attributes" ] = self ._process_bdd_attributes (item )
510532 return payload
511533
@@ -1057,12 +1079,14 @@ def start_bdd_scenario(self, feature: Feature, scenario: Scenario) -> None:
10571079 else :
10581080 feature_leaf = self ._create_leaf (LeafType .FILE , root_leaf , feature )
10591081 children_leafs [feature ] = feature_leaf
1082+ children_leafs = feature_leaf ["children" ]
10601083 rule = getattr (scenario , "rule" , None )
10611084 if rule :
10621085 if rule in children_leafs :
10631086 rule_leaf = children_leafs [rule ]
10641087 else :
10651088 rule_leaf = self ._create_leaf (LeafType .SUITE , feature_leaf , rule )
1089+ children_leafs [rule ] = rule_leaf
10661090 else :
10671091 rule_leaf = feature_leaf
10681092 children_leafs = rule_leaf ["children" ]
@@ -1074,6 +1098,7 @@ def start_bdd_scenario(self, feature: Feature, scenario: Scenario) -> None:
10741098 if background not in children_leafs :
10751099 background_leaf = self ._create_leaf (LeafType .NESTED , rule_leaf , background )
10761100 children_leafs [background ] = background_leaf
1101+
10771102 self ._remove_file_names (root_leaf )
10781103 self ._generate_names (root_leaf )
10791104 if not self ._config .rp_hierarchy_code :
0 commit comments