Skip to content

Commit

Permalink
[6.15.z] Color code and sort Jira comment based on the test result. (S…
Browse files Browse the repository at this point in the history
…atelliteQE#15727)

Color code and sort Jira comment based on the test result. (SatelliteQE#15687)

(cherry picked from commit 2c2cd3b)

Co-authored-by: Jameer Pathan <[email protected]>
  • Loading branch information
Satellite-QE and jameerpathan111 authored Jul 22, 2024
1 parent 3b20544 commit c1b7e51
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pytest_plugins/jira_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,37 @@ def pytest_runtest_makereport(item, call):
update_issue_to_tests_map(item, blocked_by_issues, test_result)


def escape_special_characters(text):
special_chars = '[]'
for char in special_chars:
text = text.replace(char, f'\\{char}')
return text


def pytest_sessionfinish(session, exitstatus):
"""Add test result comment to related Jira issues."""
if hasattr(session.config, 'issue_to_tests_map'):
user = os.environ.get('USER')
build_url = os.environ.get('BUILD_URL')
for issue in session.config.issue_to_tests_map:
# Sort test result based on the outcome.
session.config.issue_to_tests_map[issue].sort(key=lambda x: x['outcome'])
all_tests_passed = True
comment_body = (
f'This is an automated comment from job/user: {build_url if build_url else user} for a Robottelo test run.\n'
f'Satellite/Capsule: {settings.server.version.release} Snap: {settings.server.version.snap} \n'
f'Result for tests linked with issue: {issue} \n'
)
for item in session.config.issue_to_tests_map[issue]:
comment_body += f'{item["nodeid"]} : {item["outcome"]} \n'
color_code = '{color:green}'
if item['outcome'] == 'failed':
all_tests_passed = False
color_code = '{color:red}'
# Color code test outcome
color_coded_result = f'{color_code}{item["outcome"]}{{color}}'
# Escape special characters in the node_id.
escaped_node_id = escape_special_characters(item['nodeid'])
comment_body += f'{escaped_node_id} : {color_coded_result} \n'
try:
labels = (
[{'add': JIRA_TESTS_PASSED_LABEL}, {'remove': JIRA_TESTS_FAILED_LABEL}]
Expand Down

0 comments on commit c1b7e51

Please sign in to comment.