diff --git a/lisa/notifiers/junit.py b/lisa/notifiers/junit.py index 2dcfc74805..ca9e739b15 100644 --- a/lisa/notifiers/junit.py +++ b/lisa/notifiers/junit.py @@ -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 class _TestSuiteInfo: @@ -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.") @@ -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 - 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