Skip to content

Commit 1434406

Browse files
committed
Custom Item name: WIP
1 parent c860076 commit 1434406

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

pytest_reportportal/service.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def collect_tests(self, session: Session) -> None:
360360
self._merge_code(test_tree)
361361
self._build_item_paths(test_tree, [])
362362

363-
def _get_item_name(self, name: str) -> str:
363+
def _truncate_item_name(self, name: str) -> str:
364364
"""Get name of item.
365365
366366
:param name: Test Item name
@@ -403,7 +403,7 @@ def _build_start_suite_rq(self, leaf):
403403
code_ref = str(leaf['item']) if leaf['type'] == LeafType.DIR else str(leaf['item'].fspath)
404404
parent_item_id = self._lock(leaf['parent'], lambda p: p.get('item_id')) if 'parent' in leaf else None
405405
payload = {
406-
'name': self._get_item_name(leaf['name']),
406+
'name': self._truncate_item_name(leaf['name']),
407407
'description': self._get_item_description(leaf['item']),
408408
'start_time': timestamp(),
409409
'item_type': 'SUITE',
@@ -431,6 +431,9 @@ def _create_suite_path(self, item: Item):
431431
continue
432432
self._lock(leaf, lambda p: self._create_suite(p))
433433

434+
def _get_item_name(self, mark) -> str:
435+
pass
436+
434437
def _get_code_ref(self, item):
435438
# Generate script path from work dir, use only backslashes to have the
436439
# same path on different systems and do not affect Test Case ID on
@@ -451,7 +454,7 @@ def _get_code_ref(self, item):
451454
class_path = '.'.join(classes)
452455
return '{0}:{1}'.format(path, class_path)
453456

454-
def _get_test_case_id(self, mark, leaf):
457+
def _get_test_case_id(self, mark, leaf) -> str:
455458
parameters = leaf.get('parameters', None)
456459
parameterized = True
457460
selected_params = None
@@ -515,7 +518,7 @@ def _get_issue_description_line(self, mark, default_url):
515518
issues += template.format(issue_id=issue_id, url=issue_url)
516519
return ISSUE_DESCRIPTION_LINE_TEMPLATE.format(reason, issues)
517520

518-
def _get_issue(self, mark):
521+
def _get_issue(self, mark) -> Issue:
519522
"""Add issues description and issue_type to the test item.
520523
521524
:param mark: pytest mark
@@ -554,6 +557,17 @@ def _to_attribute(self, attribute_tuple):
554557
else:
555558
return {'value': attribute_tuple[1]}
556559

560+
def _process_item_name(self, item) -> str:
561+
"""
562+
Process Item Name if set.
563+
564+
:param item: Pytest.Item
565+
:return: Item Name string
566+
"""
567+
names = [m for m in item.iter_markers() if m.name == 'name']
568+
if len(names) > 0:
569+
return self._get_item_name(names[0])
570+
557571
def _get_parameters(self, item):
558572
"""
559573
Get params of item.
@@ -575,7 +589,7 @@ def _process_test_case_id(self, leaf):
575589
return self._get_test_case_id(tc_ids[0], leaf)
576590
return self._get_test_case_id(None, leaf)
577591

578-
def _process_issue(self, item):
592+
def _process_issue(self, item) -> Issue:
579593
"""
580594
Process Issue if set.
581595
@@ -611,20 +625,21 @@ def _process_attributes(self, item):
611625
return [self._to_attribute(attribute)
612626
for attribute in attributes]
613627

614-
def _process_metadata_item_start(self, leaf):
628+
def _process_metadata_item_start(self, leaf: Dict[str, Any]):
615629
"""
616630
Process all types of item metadata for its start event.
617631
618632
:param leaf: item context
619633
"""
620634
item = leaf['item']
635+
leaf['name'] = self._get_item_name(item)
621636
leaf['parameters'] = self._get_parameters(item)
622637
leaf['code_ref'] = self._get_code_ref(item)
623638
leaf['test_case_id'] = self._process_test_case_id(leaf)
624639
leaf['issue'] = self._process_issue(item)
625640
leaf['attributes'] = self._process_attributes(item)
626641

627-
def _process_metadata_item_finish(self, leaf):
642+
def _process_metadata_item_finish(self, leaf: Dict[str, Any]):
628643
"""
629644
Process all types of item metadata for its finish event.
630645
@@ -637,7 +652,7 @@ def _process_metadata_item_finish(self, leaf):
637652
def _build_start_step_rq(self, leaf):
638653
payload = {
639654
'attributes': leaf.get('attributes', None),
640-
'name': self._get_item_name(leaf['name']),
655+
'name': self._truncate_item_name(leaf['name']),
641656
'description': self._get_item_description(leaf['item']),
642657
'start_time': timestamp(),
643658
'item_type': 'STEP',
@@ -674,10 +689,6 @@ def start_pytest_item(self, test_item: Optional[Item] = None):
674689
self.start()
675690

676691
self._create_suite_path(test_item)
677-
678-
# Item type should be sent as "STEP" until we upgrade to RPv6.
679-
# Details at:
680-
# https://github.com/reportportal/agent-Python-RobotFramework/issues/56
681692
current_leaf = self._tree_path[test_item][-1]
682693
self._process_metadata_item_start(current_leaf)
683694
item_id = self._start_step(self._build_start_step_rq(current_leaf))

0 commit comments

Comments
 (0)