Skip to contentSkip to conversation

kunit: tool: fix --json output for skipped tests

PATCH In review Daniel Latypov 3 participants 3 messages Oct 8, 2021 – Dec 7, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kunit: tool: fix --json output for skipped tests

Currently, KUnit will report SKIPPED tests as having failed if one uses --json.

Add the missing if statement to set the appropriate status ("SKIP"). See https://api.kernelci.org/schema-test-case.html:

  "status": {
      "type": "string",
      "description": "The status of the execution of this test case",
      "enum": ["PASS", "FAIL", "SKIP", "ERROR"],
      "default": "PASS"

},
with this, we now can properly produce all four of the statuses.

Fixes 5acaf6031f53 ("kunit: tool: Support skipped tests in kunit_tool")
---
 tools/testing/kunit/kunit_json.py      | 2 ++
 tools/testing/kunit/kunit_tool_test.py | 6 ++++++
 2 files changed, 8 insertions(+)
tools/testing/kunit/kunit_json.py +2 -0
index 746bec72b9ac..b6e66c5d64d1 100644
@@ -30,6 +30,8 @@ def _get_group_json(test: Test, def_config: str,
 			test_case = {"name": subtest.name, "status": "FAIL"}
 			if subtest.status == TestStatus.SUCCESS:
 				test_case["status"] = "PASS"
+			elif subtest.status == TestStatus.SKIPPED:
+				test_case["status"] = "SKIP"
 			elif subtest.status == TestStatus.TEST_CRASHED:
 				test_case["status"] = "ERROR"
 			test_cases.append(test_case)
tools/testing/kunit/kunit_tool_test.py +6 -0
index 77e61b0a40e8..b3cc0227843c 100755
@@ -426,6 +426,12 @@ class KUnitJsonTest(unittest.TestCase):
 			{'name': 'example_simple_test', 'status': 'ERROR'},
 			result["sub_groups"][1]["test_cases"][0])
 
+	def test_skipped_test_json(self):
+		result = self._json_for('test_skip_tests.log')
+		self.assertEqual(
+			{'name': 'example_skip_test', 'status': 'SKIP'},
+			result["sub_groups"][1]["test_cases"][1])
+
 	def test_no_tests_json(self):
 		result = self._json_for('test_is_test_passed-no_tests_run_with_header.log')
 		self.assertEqual(0, len(result['sub_groups']))

base-commit: 4a86e2973c31902a2a72f4f25f99b2367188ec5d

Signature · 1 line
2.33.0.882.g93a45727a2-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Daniel Latypov

Currently, KUnit will report SKIPPED tests as having failed if one uses --json.

Add the missing if statement to set the appropriate status ("SKIP"). See https://api.kernelci.org/schema-test-case.html:

  "status": {
      "type": "string",
      "description": "The status of the execution of this test case",
      "enum": ["PASS", "FAIL", "SKIP", "ERROR"],
      "default": "PASS"
Quoted 6 lines

},
with this, we now can properly produce all four of the statuses.

Fixes 5acaf6031f53 ("kunit: tool: Support skipped tests in kunit_tool")

---

Ah: thanks! I totally missed this!

-- David

Quoted 39 lines
 tools/testing/kunit/kunit_json.py      | 2 ++
 tools/testing/kunit/kunit_tool_test.py | 6 ++++++
 2 files changed, 8 insertions(+)
tools/testing/kunit/kunit_json.py +2 -0
index 746bec72b9ac..b6e66c5d64d1 100644
@@ -30,6 +30,8 @@ def _get_group_json(test: Test, def_config: str,
                        test_case = {"name": subtest.name, "status": "FAIL"}
                        if subtest.status == TestStatus.SUCCESS:
                                test_case["status"] = "PASS"
+                       elif subtest.status == TestStatus.SKIPPED:
+                               test_case["status"] = "SKIP"
                        elif subtest.status == TestStatus.TEST_CRASHED:
                                test_case["status"] = "ERROR"
                        test_cases.append(test_case)
tools/testing/kunit/kunit_tool_test.py +6 -0
index 77e61b0a40e8..b3cc0227843c 100755
@@ -426,6 +426,12 @@ class KUnitJsonTest(unittest.TestCase):
                        {'name': 'example_simple_test', 'status': 'ERROR'},
                        result["sub_groups"][1]["test_cases"][0])
 
+       def test_skipped_test_json(self):
+               result = self._json_for('test_skip_tests.log')
+               self.assertEqual(
+                       {'name': 'example_skip_test', 'status': 'SKIP'},
+                       result["sub_groups"][1]["test_cases"][1])
+
        def test_no_tests_json(self):
                result = self._json_for('test_is_test_passed-no_tests_run_with_header.log')
                self.assertEqual(0, len(result['sub_groups']))

base-commit: 4a86e2973c31902a2a72f4f25f99b2367188ec5d --
2.33.0.882.g93a45727a2-goog

Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel Latypov
Quoted 11 lines · Daniel Latypov

Currently, KUnit will report SKIPPED tests as having failed if one uses --json.

Add the missing if statement to set the appropriate status ("SKIP"). See https://api.kernelci.org/schema-test-case.html:

  "status": {
      "type": "string",
      "description": "The status of the execution of this test case",
      "enum": ["PASS", "FAIL", "SKIP", "ERROR"],
      "default": "PASS"
Quoted 5 lines

},
with this, we now can properly produce all four of the statuses.

Fixes 5acaf6031f53 ("kunit: tool: Support skipped tests in kunit_tool")

Thanks!