@@ -370,7 +370,7 @@ def collect_tests(self, session: Session) -> None:
370370 self ._merge_code (test_tree )
371371 self ._build_item_paths (test_tree , [])
372372
373- def _get_item_name (self , name : str ) -> str :
373+ def _truncate_item_name (self , name : str ) -> str :
374374 """Get name of item.
375375
376376 :param name: Test Item name
@@ -413,7 +413,7 @@ def _build_start_suite_rq(self, leaf):
413413 code_ref = str (leaf ['item' ]) if leaf ['type' ] == LeafType .DIR else str (leaf ['item' ].fspath )
414414 parent_item_id = self ._lock (leaf ['parent' ], lambda p : p .get ('item_id' )) if 'parent' in leaf else None
415415 payload = {
416- 'name' : self ._get_item_name (leaf ['name' ]),
416+ 'name' : self ._truncate_item_name (leaf ['name' ]),
417417 'description' : self ._get_item_description (leaf ['item' ]),
418418 'start_time' : timestamp (),
419419 'item_type' : 'SUITE' ,
@@ -441,6 +441,9 @@ def _create_suite_path(self, item: Item):
441441 continue
442442 self ._lock (leaf , lambda p : self ._create_suite (p ))
443443
444+ def _get_item_name (self , mark ) -> Optional [str ]:
445+ pass
446+
444447 def _get_code_ref (self , item ):
445448 # Generate script path from work dir, use only backslashes to have the
446449 # same path on different systems and do not affect Test Case ID on
@@ -461,7 +464,7 @@ def _get_code_ref(self, item):
461464 class_path = '.' .join (classes )
462465 return '{0}:{1}' .format (path , class_path )
463466
464- def _get_test_case_id (self , mark , leaf ):
467+ def _get_test_case_id (self , mark , leaf ) -> str :
465468 parameters = leaf .get ('parameters' , None )
466469 parameterized = True
467470 selected_params = None
@@ -521,45 +524,39 @@ def _get_issue_description_line(self, mark, default_url):
521524 issues = ""
522525 for i , issue_id in enumerate (issue_ids ):
523526 issue_url = issue_urls [i ]
524- template = ISSUE_DESCRIPTION_URL_TEMPLATE if issue_url \
525- else ISSUE_DESCRIPTION_ID_TEMPLATE
526- issues += template .format (issue_id = issue_id ,
527- url = issue_url )
527+ template = ISSUE_DESCRIPTION_URL_TEMPLATE if issue_url else ISSUE_DESCRIPTION_ID_TEMPLATE
528+ issues += template .format (issue_id = issue_id , url = issue_url )
528529 return ISSUE_DESCRIPTION_LINE_TEMPLATE .format (reason , issues )
529530
530- def _get_issue (self , mark ):
531+ def _get_issue (self , mark ) -> Issue :
531532 """Add issues description and issue_type to the test item.
532533
533534 :param mark: pytest mark
534535 :return: Issue object
535536 """
536537 default_url = self ._config .rp_bts_issue_url
537538
538- issue_description_line = \
539- self ._get_issue_description_line (mark , default_url )
539+ issue_description_line = self ._get_issue_description_line (mark , default_url )
540540
541541 # Set issue_type only for first issue mark
542542 issue_short_name = None
543543 if "issue_type" in mark .kwargs :
544544 issue_short_name = mark .kwargs ["issue_type" ]
545545
546546 # default value
547- issue_short_name = "TI" if issue_short_name is None else \
548- issue_short_name
547+ issue_short_name = "TI" if issue_short_name is None else issue_short_name
549548
550549 registered_issues = self .issue_types
551550 issue = None
552551 if issue_short_name in registered_issues :
553- issue = Issue (registered_issues [issue_short_name ],
554- issue_description_line )
552+ issue = Issue (registered_issues [issue_short_name ], issue_description_line )
555553
556554 if issue and self ._config .rp_bts_project and self ._config .rp_bts_url :
557555 issue_ids = self ._get_issue_ids (mark )
558556 issue_urls = self ._get_issue_urls (mark , default_url )
559557 for issue_id , issue_url in zip (issue_ids , issue_urls ):
560558 issue .external_issue_add (
561- ExternalIssue (bts_url = self ._config .rp_bts_url ,
562- bts_project = self ._config .rp_bts_project ,
559+ ExternalIssue (bts_url = self ._config .rp_bts_url , bts_project = self ._config .rp_bts_project ,
563560 ticket_id = issue_id , url = issue_url )
564561 )
565562 return issue
@@ -570,6 +567,22 @@ def _to_attribute(self, attribute_tuple):
570567 else :
571568 return {'value' : attribute_tuple [1 ]}
572569
570+ def _process_item_name (self , leaf : Dict [str , Any ]) -> str :
571+ """
572+ Process Item Name if set.
573+
574+ :param leaf: item context
575+ :return: Item Name string
576+ """
577+ item = leaf ['item' ]
578+ name = leaf ['name' ]
579+ names = [m for m in item .iter_markers () if m .name == 'name' ]
580+ if len (names ) > 0 :
581+ mark_name = self ._get_item_name (names [0 ])
582+ if mark_name :
583+ name = mark_name
584+ return name
585+
573586 def _get_parameters (self , item ):
574587 """
575588 Get params of item.
@@ -591,7 +604,7 @@ def _process_test_case_id(self, leaf):
591604 return self ._get_test_case_id (tc_ids [0 ], leaf )
592605 return self ._get_test_case_id (None , leaf )
593606
594- def _process_issue (self , item ):
607+ def _process_issue (self , item ) -> Issue :
595608 """
596609 Process Issue if set.
597610
@@ -627,20 +640,21 @@ def _process_attributes(self, item):
627640 return [self ._to_attribute (attribute )
628641 for attribute in attributes ]
629642
630- def _process_metadata_item_start (self , leaf ):
643+ def _process_metadata_item_start (self , leaf : Dict [ str , Any ] ):
631644 """
632645 Process all types of item metadata for its start event.
633646
634647 :param leaf: item context
635648 """
636649 item = leaf ['item' ]
650+ leaf ['name' ] = self ._process_item_name (leaf )
637651 leaf ['parameters' ] = self ._get_parameters (item )
638652 leaf ['code_ref' ] = self ._get_code_ref (item )
639653 leaf ['test_case_id' ] = self ._process_test_case_id (leaf )
640654 leaf ['issue' ] = self ._process_issue (item )
641655 leaf ['attributes' ] = self ._process_attributes (item )
642656
643- def _process_metadata_item_finish (self , leaf ):
657+ def _process_metadata_item_finish (self , leaf : Dict [ str , Any ] ):
644658 """
645659 Process all types of item metadata for its finish event.
646660
@@ -653,7 +667,7 @@ def _process_metadata_item_finish(self, leaf):
653667 def _build_start_step_rq (self , leaf ):
654668 payload = {
655669 'attributes' : leaf .get ('attributes' , None ),
656- 'name' : self ._get_item_name (leaf ['name' ]),
670+ 'name' : self ._truncate_item_name (leaf ['name' ]),
657671 'description' : self ._get_item_description (leaf ['item' ]),
658672 'start_time' : timestamp (),
659673 'item_type' : 'STEP' ,
@@ -690,10 +704,6 @@ def start_pytest_item(self, test_item: Optional[Item] = None):
690704 self .start ()
691705
692706 self ._create_suite_path (test_item )
693-
694- # Item type should be sent as "STEP" until we upgrade to RPv6.
695- # Details at:
696- # https://github.com/reportportal/agent-Python-RobotFramework/issues/56
697707 current_leaf = self ._tree_path [test_item ][- 1 ]
698708 self ._process_metadata_item_start (current_leaf )
699709 item_id = self ._start_step (self ._build_start_step_rq (current_leaf ))
0 commit comments