-
Notifications
You must be signed in to change notification settings - Fork 179
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
base: main
Are you sure you want to change the base?
Update junit.py #3496
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,12 @@ 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 | ||
# show 'message' for failed cases and 'stacktrace' | ||
include_failed_messages: bool = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When should it be set to False? If no scenario, it can be included always. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default behavior is to include messages and stacktraces for Failed tests/subcases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the scenarios, which want set failed/skippped to false, and set passed to true. So the three flags are not needed. The logic always include stackstrace for failed and skipped, but never for passed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. understood. I will modify code to only implement logic for successful test cases. |
||
# show 'message' for skipped cases | ||
include_skipped_messages: bool = True | ||
|
||
|
||
class _TestSuiteInfo: | ||
|
@@ -291,6 +297,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.") | ||
|
@@ -302,18 +310,27 @@ def _add_test_case_result( | |
|
||
if message.status == TestStatus.FAILED: | ||
failure = ET.SubElement(testcase, "failure") | ||
failure.attrib["message"] = message.message | ||
failure.text = message.stacktrace | ||
|
||
if runbook.include_failed_messages: | ||
failure.attrib["message"] = message.message | ||
# failure.text = message.stacktrace | ||
squirrelsc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if str(message.stacktrace) != "": | ||
squirrelsc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
failure.attrib["stacktrace"] = str(message.stacktrace) | ||
squirrelsc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 runbook.include_skipped_messages: | ||
skipped.attrib["message"] = message.message | ||
if str(message.stacktrace) != "": | ||
skipped.attrib["stacktrace"] = str(message.stacktrace) | ||
# Only add XML sub element if include_passed_messages is True in runbook | ||
# By default, its assumed subtest is a pass | ||
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 str(message.stacktrace) != "": | ||
passed.attrib["stacktrace"] = str(message.stacktrace) | ||
testsuite_info.test_count += 1 | ||
|
||
# Write out current results to file. | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.