Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update junit.py #3496

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lisa/notifiers/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class JUnitSchema(schema.Notifier):
path: str = "lisa.junit.xml"
# respect the original behavior, include subtest by default
include_subtest: bool = True
# show passed case 'message' and 'stacktraces'
include_passed_messages: bool = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need to be False by default, so the logic is more consistent for different types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I marked it false to ensure current output is not modified in any way. This is because i expect users to be parsing this output in their implementation of LISA.
Marking passed and skipped flag as false by default allows us to maintain some level of compat with existing implementation while allowing customization for new implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no scenario needs the stack trace for passed test cases, it doesn't need the flag.



class _TestSuiteInfo:
Expand Down Expand Up @@ -291,6 +293,8 @@ def _add_test_case_result(
class_name: str,
elapsed: float,
) -> None:
# Creating a JunitSchema object to read the passed parameters to Junit class
runbook: JUnitSchema = cast(JUnitSchema, self.runbook)
testsuite_info = self._testsuites_info.get(suite_full_name)
if not testsuite_info:
raise LisaException("Test suite not started.")
Expand All @@ -304,15 +308,21 @@ def _add_test_case_result(
failure = ET.SubElement(testcase, "failure")
failure.attrib["message"] = message.message
failure.text = message.stacktrace

testsuite_info.failed_count += 1
squirrelsc marked this conversation as resolved.
Show resolved Hide resolved

elif (
message.status == TestStatus.SKIPPED
or message.status == TestStatus.ATTEMPTED
):
elif message.status in [TestStatus.SKIPPED, TestStatus.ATTEMPTED]:
skipped = ET.SubElement(testcase, "skipped")
skipped.attrib["message"] = message.message
if message.stacktrace:
skipped.text = str(message.stacktrace)
# Only add XML sub element if include_passed_messages is True in runbook
# By default, its assumed subtest is a pass as per Junit schema
elif message.status == TestStatus.PASSED and runbook.include_passed_messages:
passed = ET.SubElement(testcase, "passed")
passed.attrib["message"] = message.message
# passed.text = message.stacktrace
if message.stacktrace:
passed.text = str(message.stacktrace)

testsuite_info.test_count += 1

Expand Down
Loading