Skip to content

Commit

Permalink
Custom Item name: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 2, 2024
1 parent c860076 commit 1434406
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions pytest_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def collect_tests(self, session: Session) -> None:
self._merge_code(test_tree)
self._build_item_paths(test_tree, [])

def _get_item_name(self, name: str) -> str:
def _truncate_item_name(self, name: str) -> str:
"""Get name of item.
:param name: Test Item name
Expand Down Expand Up @@ -403,7 +403,7 @@ def _build_start_suite_rq(self, leaf):
code_ref = str(leaf['item']) if leaf['type'] == LeafType.DIR else str(leaf['item'].fspath)
parent_item_id = self._lock(leaf['parent'], lambda p: p.get('item_id')) if 'parent' in leaf else None
payload = {
'name': self._get_item_name(leaf['name']),
'name': self._truncate_item_name(leaf['name']),
'description': self._get_item_description(leaf['item']),
'start_time': timestamp(),
'item_type': 'SUITE',
Expand Down Expand Up @@ -431,6 +431,9 @@ def _create_suite_path(self, item: Item):
continue
self._lock(leaf, lambda p: self._create_suite(p))

def _get_item_name(self, mark) -> str:
pass

def _get_code_ref(self, item):
# Generate script path from work dir, use only backslashes to have the
# same path on different systems and do not affect Test Case ID on
Expand All @@ -451,7 +454,7 @@ def _get_code_ref(self, item):
class_path = '.'.join(classes)
return '{0}:{1}'.format(path, class_path)

def _get_test_case_id(self, mark, leaf):
def _get_test_case_id(self, mark, leaf) -> str:
parameters = leaf.get('parameters', None)
parameterized = True
selected_params = None
Expand Down Expand Up @@ -515,7 +518,7 @@ def _get_issue_description_line(self, mark, default_url):
issues += template.format(issue_id=issue_id, url=issue_url)
return ISSUE_DESCRIPTION_LINE_TEMPLATE.format(reason, issues)

def _get_issue(self, mark):
def _get_issue(self, mark) -> Issue:
"""Add issues description and issue_type to the test item.
:param mark: pytest mark
Expand Down Expand Up @@ -554,6 +557,17 @@ def _to_attribute(self, attribute_tuple):
else:
return {'value': attribute_tuple[1]}

def _process_item_name(self, item) -> str:
"""
Process Item Name if set.
:param item: Pytest.Item
:return: Item Name string
"""
names = [m for m in item.iter_markers() if m.name == 'name']
if len(names) > 0:
return self._get_item_name(names[0])

def _get_parameters(self, item):
"""
Get params of item.
Expand All @@ -575,7 +589,7 @@ def _process_test_case_id(self, leaf):
return self._get_test_case_id(tc_ids[0], leaf)
return self._get_test_case_id(None, leaf)

def _process_issue(self, item):
def _process_issue(self, item) -> Issue:
"""
Process Issue if set.
Expand Down Expand Up @@ -611,20 +625,21 @@ def _process_attributes(self, item):
return [self._to_attribute(attribute)
for attribute in attributes]

def _process_metadata_item_start(self, leaf):
def _process_metadata_item_start(self, leaf: Dict[str, Any]):
"""
Process all types of item metadata for its start event.
:param leaf: item context
"""
item = leaf['item']
leaf['name'] = self._get_item_name(item)
leaf['parameters'] = self._get_parameters(item)
leaf['code_ref'] = self._get_code_ref(item)
leaf['test_case_id'] = self._process_test_case_id(leaf)
leaf['issue'] = self._process_issue(item)
leaf['attributes'] = self._process_attributes(item)

def _process_metadata_item_finish(self, leaf):
def _process_metadata_item_finish(self, leaf: Dict[str, Any]):
"""
Process all types of item metadata for its finish event.
Expand All @@ -637,7 +652,7 @@ def _process_metadata_item_finish(self, leaf):
def _build_start_step_rq(self, leaf):
payload = {
'attributes': leaf.get('attributes', None),
'name': self._get_item_name(leaf['name']),
'name': self._truncate_item_name(leaf['name']),
'description': self._get_item_description(leaf['item']),
'start_time': timestamp(),
'item_type': 'STEP',
Expand Down Expand Up @@ -674,10 +689,6 @@ def start_pytest_item(self, test_item: Optional[Item] = None):
self.start()

self._create_suite_path(test_item)

# Item type should be sent as "STEP" until we upgrade to RPv6.
# Details at:
# https://github.com/reportportal/agent-Python-RobotFramework/issues/56
current_leaf = self._tree_path[test_item][-1]
self._process_metadata_item_start(current_leaf)
item_id = self._start_step(self._build_start_step_rq(current_leaf))
Expand Down

0 comments on commit 1434406

Please sign in to comment.