Skip to content

Commit

Permalink
Take message and content for details, but avoid duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Oct 4, 2022
1 parent f30b1ea commit 53f77c2
Show file tree
Hide file tree
Showing 24 changed files with 1,934 additions and 782 deletions.
26 changes: 21 additions & 5 deletions python/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,13 @@ def get_long_summary_with_digest_md(stats: UnitTestRunResultsOrDeltaResults,


def get_case_messages(case_results: UnitTestCaseResults) -> CaseMessages:
""" Re-index cases from test+state to test+state+message. """
messages = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
for key in case_results:
for state in case_results[key]:
for case in case_results[key][state]:
for test in case_results:
for state in case_results[test]:
for case in case_results[test][state]:
message = case.message if case.result in ['skipped', 'disabled'] else case.content
messages[key][state][message].append(case)
messages[test][state][message].append(case)
return CaseMessages(messages)


Expand Down Expand Up @@ -791,6 +792,21 @@ def get_case_annotation(messages: CaseMessages,
'notice'
)

def message_is_contained_in_content(message: Optional[str], content: Optional[str]) -> bool:
# ignore new lines and any leading or trailing white spaces
if content and message:
content = re.sub(r'\s+', ' ', content.strip())
message = re.sub(r'\s+', ' ', message.strip())
return content.startswith(message)
return False

# pick details from message and content, but try to avoid redundancy (e.g. when content repeats message)
details = [detail.rstrip()
for detail in ([case.content]
if message_is_contained_in_content(case.message, case.content)
else [case.message, case.content])
if detail and detail.rstrip()]

return Annotation(
path=test_file or class_name or '/',
start_line=line,
Expand All @@ -800,7 +816,7 @@ def get_case_annotation(messages: CaseMessages,
annotation_level=level,
message='\n'.join(sorted(same_result_files)),
title=title,
raw_details=message
raw_details='\n'.join(details) if details else None
)


Expand Down
12 changes: 9 additions & 3 deletions python/publish/unittestresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,17 @@ def get_test_results(parsed_results: ParsedUnitTestResultsWithCommit,
cases_errors = [case for case in cases if case.result == 'error']
cases_time = sum([case.time or 0 for case in cases])

# group cases by tests
# index cases by tests and state
cases_results = UnitTestCaseResults()
for case in cases:
key = (case.test_file if dedup_classes_by_file_name else None, case.class_name, case.test_name)
cases_results[key][case.result if case.result != 'disabled' else 'skipped'].append(case)
# index by test file name (when de-duplicating by file name), class name and test name
test = (case.test_file if dedup_classes_by_file_name else None, case.class_name, case.test_name)

# second index by state
state = case.result if case.result != 'disabled' else 'skipped'

# collect cases of test and state
cases_results[test][state].append(case)

test_results = dict()
for test, states in cases_results.items():
Expand Down
4 changes: 2 additions & 2 deletions python/test/files/junit-xml/junit.multiresult.annotations
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'annotation_level': 'failure',
'message': 'junit.multiresult.xml',
'title': 'test that errors (test class) with error',
'raw_details': 'stdout'
'raw_details': 'test teardown failure\nstdout'
},
{
'path': 'test class',
Expand All @@ -49,7 +49,7 @@
'annotation_level': 'warning',
'message': 'junit.multiresult.xml',
'title': 'test that fails (test class) failed',
'raw_details': 'Assertion failed'
'raw_details': 'test failure\nAssertion failed'
},
{
'path': '.github',
Expand Down
2 changes: 1 addition & 1 deletion python/test/files/junit-xml/pytest/junit.fail.annotations
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'do_test_rsh_events\n self.do_test_rsh(command, 143, '
'events=events)\n test_spark.py:852: in do_test_rsh\n '
' self.assertEqual(expected_result, res)\n '
' E AssertionError: 143 != 0\n '
' E AssertionError: 143 != 0'
},
{
'path': '.github',
Expand Down
90 changes: 70 additions & 20 deletions python/test/files/junit-xml/tst/disabled.annotations
Original file line number Diff line number Diff line change
Expand Up @@ -41,159 +41,209 @@
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'factorial_of_value_from_fixture failed'
'title': 'factorial_of_value_from_fixture failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/main.cpp:72: error: '
'check_eq(3628800, 3628801)'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'positive_arguments_must_produce_expected_result failed'
'title': 'positive_arguments_must_produce_expected_result failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/main.cpp:45: error: check_ne(6, '
'6)hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'failure',
'message': 'tst/disabled.xml',
'title': 'test_which_throws_unknown_exception with error'
'title': 'test_which_throws_unknown_exception with error',
'raw_details': 'uncaught (anonymous namespace)::some_unknown_exception'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'positive_arguments_must_produce_expected_result[2] failed'
'title': 'positive_arguments_must_produce_expected_result[2] failed',
'raw_details': '/home/ivan/prj/tst/tests/failed/main.cpp:85: error: check(false)'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'factorial_of_value_from_fixture[0] failed'
'title': 'factorial_of_value_from_fixture[0] failed',
'raw_details': '/home/ivan/prj/tst/tests/failed/main.cpp:109: error: expected 2'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'test_which_fails_check_eq_with_custom_message failed'
'title': 'test_which_fails_check_eq_with_custom_message failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/main.cpp:62: error: check_eq(6, '
'7)hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_ge_print failed'
'title': 'check_ge_print failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:59: error: check_ge(2, '
'3)failed!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_ge failed'
'title': 'check_ge failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:55: error: check_ge(2, '
'3)Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_gt_print failed'
'title': 'check_gt_print failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:43: error: check_gt(2, '
'2)failed!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_lt_print failed'
'title': 'check_lt_print failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:35: error: check_lt(2, '
'2)failed!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_print failed'
'title': 'check_print failed',
'raw_details': '/home/ivan/prj/tst/tests/failed/checks.cpp:11: error: failed!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_gt failed'
'title': 'check_gt failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:39: error: check_gt(2, '
'2)Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check failed'
'title': 'check failed',
'raw_details': '/home/ivan/prj/tst/tests/failed/checks.cpp:7: error: Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_le_print failed'
'title': 'check_le_print failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:51: error: check_le(2, '
'1)failed!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_eq failed'
'title': 'check_eq failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:15: error: check_eq(1, '
'2)Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_eq_print failed'
'title': 'check_eq_print failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:19: error: check_eq(1, '
'2)failed!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_le failed'
'title': 'check_le failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:47: error: check_le(2, '
'1)Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_ne failed'
'title': 'check_ne failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:23: error: check_ne(2, '
'2)Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_lt failed'
'title': 'check_lt failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:31: error: check_lt(2, '
'2)Hello world!'
},
{
'path': '/',
'start_line': 0,
'end_line': 0,
'annotation_level': 'warning',
'message': 'tst/disabled.xml',
'title': 'check_ne_print failed'
'title': 'check_ne_print failed',
'raw_details':
'/home/ivan/prj/tst/tests/failed/checks.cpp:27: error: check_ne(2, '
'2)failed!'
},
{
'path': '.github',
Expand Down
16 changes: 10 additions & 6 deletions python/test/files/junit-xml/unsupported-unicode.annotations
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
'annotation_level': 'warning',
'message': 'unsupported-unicode.xml',
'title': 'test 4 failed',
'raw_details': 'failed\n '
'raw_details':
'Some unsupported unicode characters: '
'헴䜝헱홐㣇㿷䔭\\U0001237a\\U000214ff\\U00020109㦓\nfailed'
},
{
'path': 'test/test-5.py',
Expand All @@ -44,8 +46,8 @@
'message': 'unsupported-unicode.xml',
'title': 'test 5 failed',
'raw_details':
'Some unsupported unicode characters: '
'헴䜝헱홐㣇㿷䔭\\U0001237a\\U000214ff\\U00020109㦓\n '
'message\nSome unsupported unicode characters: '
'헴䜝헱홐㣇㿷䔭\\U0001237a\\U000214ff\\U00020109㦓'
},
{
'path': 'test/test-6.py',
Expand All @@ -54,7 +56,9 @@
'annotation_level': 'failure',
'message': 'unsupported-unicode.xml',
'title': 'test 6 with error',
'raw_details': 'error\n '
'raw_details':
'Some unsupported unicode characters: '
'헴䜝헱홐㣇㿷䔭\\U0001237a\\U000214ff\\U00020109㦓\nerror'
},
{
'path': 'test/test-7.py',
Expand All @@ -64,8 +68,8 @@
'message': 'unsupported-unicode.xml',
'title': 'test 7 with error',
'raw_details':
'Some unsupported unicode characters: '
'헴䜝헱홐㣇㿷䔭\\U0001237a\\U000214ff\\U00020109㦓\n '
'message\nSome unsupported unicode characters: '
'헴䜝헱홐㣇㿷䔭\\U0001237a\\U000214ff\\U00020109㦓'
},
{
'path': '.github',
Expand Down
4 changes: 2 additions & 2 deletions python/test/files/junit-xml/with-xml-entities.annotations
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'annotation_level': 'warning',
'message': 'with-xml-entities.xml',
'title': "Test with 'apostrophe' in the test name failed",
'raw_details': "Content with 'apostrophes'"
'raw_details': "A message with 'apostrophes'\nContent with 'apostrophes'"
},
{
'path': '/',
Expand All @@ -43,7 +43,7 @@
'annotation_level': 'failure',
'message': 'with-xml-entities.xml',
'title': 'Test with & in the test name with error',
'raw_details': 'Content with &'
'raw_details': 'A message with &\nContent with &'
},
{
'path': '.github',
Expand Down

0 comments on commit 53f77c2

Please sign in to comment.