@@ -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 , item ):
580+ """
581+ Process Issue if set.
578582
583+ :param item: Pytest.Item
584+ :return: Issue
585+ """
586+ for marker in item .iter_markers ():
587+ if marker .name == '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+ """
579597 attributes = set ()
580- 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
598+ for marker in item .iter_markers ():
585599 if marker .name == 'issue' :
586- issue = self ._get_issue (marker )
587- leaf ['issue' ] = 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,29 @@ 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 ]
614+
615+ def _process_metadata_item_start (self , leaf ):
616+ """
617+ Process all types of item metadata for its start event.
602618
603- if 'test_case_id' not in leaf :
604- leaf ['test_case_id' ] = self ._get_test_case_id (None , leaf )
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 ['issue' ] = self ._process_issue (item )
626+ leaf ['attributes' ] = self ._process_attributes (item )
627+
628+ def _process_metadata_item_finish (self , leaf ):
629+ """
630+ Process all types of item metadata for its finish event.
631+
632+ :param leaf: item context
633+ """
634+ leaf ['attributes' ] = self ._process_attributes (leaf ['item' ])
605635
606636 def _build_start_step_rq (self , leaf ):
607637 payload = {
@@ -647,7 +677,7 @@ def start_pytest_item(self, test_item=None):
647677 # Details at:
648678 # https://github.com/reportportal/agent-Python-RobotFramework/issues/56
649679 current_leaf = self ._tree_path [test_item ][- 1 ]
650- self ._process_attributes (current_leaf )
680+ self ._process_metadata_item_start (current_leaf )
651681 item_id = self ._start_step (self ._build_start_step_rq (current_leaf ))
652682 current_leaf ['item_id' ] = item_id
653683 current_leaf ['exec' ] = ExecStatus .IN_PROGRESS
@@ -683,6 +713,7 @@ def _build_finish_step_rq(self, leaf):
683713 if status == 'PASSED' :
684714 issue = None
685715 payload = {
716+ 'attributes' : leaf .get ('attributes' , None ),
686717 'end_time' : timestamp (),
687718 'status' : status ,
688719 'issue' : issue ,
@@ -741,6 +772,7 @@ def finish_pytest_item(self, test_item):
741772
742773 path = self ._tree_path [test_item ]
743774 leaf = path [- 1 ]
775+ self ._process_metadata_item_finish (leaf )
744776 self ._finish_step (self ._build_finish_step_rq (leaf ))
745777 leaf ['exec' ] = ExecStatus .FINISHED
746778 self ._finish_parents (leaf )
@@ -759,7 +791,9 @@ def finish_suites(self):
759791 at once.
760792 """
761793 # Ensure there is no running items
762- while len (self ._get_items (ExecStatus .IN_PROGRESS )) > 0 :
794+ finish_time = time ()
795+ while len (self ._get_items (ExecStatus .IN_PROGRESS )) > 0 \
796+ and time () - finish_time <= self ._config .rp_launch_timeout :
763797 sleep (0.1 )
764798 skipped_items = self ._get_items (ExecStatus .CREATED )
765799 for item in skipped_items :
0 commit comments