@@ -515,6 +515,7 @@ def _get_issue(self, mark):
515515 """Add issues description and issue_type to the test item.
516516
517517 :param mark: pytest mark
518+ :return: Issue object
518519 """
519520 default_url = self ._config .rp_issue_system_url
520521
@@ -562,29 +563,40 @@ def _get_parameters(self, item):
562563 """
563564 return item .callspec .params if hasattr (item , 'callspec' ) else None
564565
565- def _process_attributes (self , leaf ):
566+ def _process_test_case_id (self , leaf ):
566567 """
567- Process all types of attributes of item .
568+ Process Test Case ID if set .
568569
569570 :param leaf: item context
571+ :return: Test Case ID string
570572 """
571- item = leaf ['item' ]
573+ for marker in leaf ['item' ].iter_markers ():
574+ if marker .name == 'tc_id' :
575+ return self ._get_test_case_id (marker , leaf )
572576
573- parameters = self ._get_parameters (item )
574- leaf ['parameters' ] = parameters
577+ return self ._get_test_case_id (None , leaf )
575578
576- code_ref = self ._get_code_ref (item )
577- leaf ['code_ref' ] = code_ref
579+ def _process_issue (self , leaf ):
580+ """
581+ Process Issue if set.
578582
579- attributes = set ()
583+ :param leaf: item context
584+ :return: Issue
585+ """
580586 for marker in leaf ['item' ].iter_markers ():
581- if marker .name == 'tc_id' :
582- test_case_id = self ._get_test_case_id (marker , leaf )
583- leaf ['test_case_id' ] = test_case_id
584- continue
585587 if marker .name == 'issue' :
586- issue = self ._get_issue (marker )
587- leaf ['issue' ] = issue
588+ return self ._get_issue (marker )
589+
590+ def _process_attributes (self , item ):
591+ """
592+ Process attributes of item.
593+
594+ :param item: Pytest.Item
595+ :return: a set of attributes
596+ """
597+ attributes = set ()
598+ for marker in item .iter_markers ():
599+ if marker .name == 'issue' :
588600 if self ._config .rp_issue_id_marks :
589601 for issue_id in self ._get_issue_ids (marker ):
590602 attributes .add ((marker .name , issue_id ))
@@ -597,11 +609,28 @@ def _process_attributes(self, leaf):
597609 else :
598610 attributes .add ((None , marker .name ))
599611
600- leaf [ 'attributes' ] = [self ._to_attribute (attribute )
601- for attribute in attributes ]
612+ return [self ._to_attribute (attribute )
613+ for attribute in attributes ]
602614
603- if 'test_case_id' not in leaf :
604- leaf ['test_case_id' ] = self ._get_test_case_id (None , leaf )
615+ def _process_metadata_item_start (self , leaf ):
616+ """
617+ Process all types of item metadata for its start event.
618+
619+ :param leaf: item context
620+ """
621+ item = leaf ['item' ]
622+ leaf ['parameters' ] = self ._get_parameters (item )
623+ leaf ['code_ref' ] = self ._get_code_ref (item )
624+ leaf ['test_case_id' ] = self ._process_test_case_id (leaf )
625+ leaf ['attributes' ] = self ._process_attributes (item )
626+
627+ def _process_metadata_item_finish (self , leaf ):
628+ """
629+ Process all types of item metadata for its finish event.
630+
631+ :param leaf: item context
632+ """
633+ leaf ['attributes' ] = self ._process_attributes (leaf ['item' ])
605634
606635 def _build_start_step_rq (self , leaf ):
607636 payload = {
@@ -647,7 +676,7 @@ def start_pytest_item(self, test_item=None):
647676 # Details at:
648677 # https://github.com/reportportal/agent-Python-RobotFramework/issues/56
649678 current_leaf = self ._tree_path [test_item ][- 1 ]
650- self ._process_attributes (current_leaf )
679+ self ._process_metadata_item_start (current_leaf )
651680 item_id = self ._start_step (self ._build_start_step_rq (current_leaf ))
652681 current_leaf ['item_id' ] = item_id
653682 current_leaf ['exec' ] = ExecStatus .IN_PROGRESS
@@ -742,7 +771,7 @@ def finish_pytest_item(self, test_item):
742771
743772 path = self ._tree_path [test_item ]
744773 leaf = path [- 1 ]
745- self ._process_attributes (leaf )
774+ self ._process_metadata_item_finish (leaf )
746775 self ._finish_step (self ._build_finish_step_rq (leaf ))
747776 leaf ['exec' ] = ExecStatus .FINISHED
748777 self ._finish_parents (leaf )
0 commit comments