Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit: tool: test: Rename test_data_path() to _test_data_path()

Running the KUnit testsuite through pytest fails, as the function
test_data_path() is recognized as a test function. Its execution fails
as pytest tries to resolve the 'path' argument as a fixture which does
not exist.

Rename the function, so the helper function is not incorrectly
recognized as a test function.

Link: https://lore.kernel.org/r/20260107015936.2316047-1-davidgow@google.com
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Thomas Weißschuh and committed by
Shuah Khan
1cabad3a ab150c2b

+28 -28
+28 -28
tools/testing/kunit/kunit_tool_test.py
··· 36 36 def tearDownModule(): 37 37 shutil.rmtree(test_tmpdir) 38 38 39 - def test_data_path(path): 39 + def _test_data_path(path): 40 40 return os.path.join(abs_test_data_dir, path) 41 41 42 42 class KconfigTest(unittest.TestCase): ··· 52 52 self.assertFalse(kconfig1.is_subset_of(kconfig0)) 53 53 54 54 def test_read_from_file(self): 55 - kconfig_path = test_data_path('test_read_from_file.kconfig') 55 + kconfig_path = _test_data_path('test_read_from_file.kconfig') 56 56 57 57 kconfig = kunit_config.parse_file(kconfig_path) 58 58 ··· 98 98 raise AssertionError(f'"{needle}" not found in {list(backup)}!') 99 99 100 100 def test_output_isolated_correctly(self): 101 - log_path = test_data_path('test_output_isolated_correctly.log') 101 + log_path = _test_data_path('test_output_isolated_correctly.log') 102 102 with open(log_path) as file: 103 103 result = kunit_parser.extract_tap_lines(file.readlines()) 104 104 self.assertContains('TAP version 14', result) ··· 109 109 self.assertContains('ok 1 - example', result) 110 110 111 111 def test_output_with_prefix_isolated_correctly(self): 112 - log_path = test_data_path('test_pound_sign.log') 112 + log_path = _test_data_path('test_pound_sign.log') 113 113 with open(log_path) as file: 114 114 result = kunit_parser.extract_tap_lines(file.readlines()) 115 115 self.assertContains('TAP version 14', result) ··· 138 138 self.assertContains('ok 3 - string-stream-test', result) 139 139 140 140 def test_parse_successful_test_log(self): 141 - all_passed_log = test_data_path('test_is_test_passed-all_passed.log') 141 + all_passed_log = _test_data_path('test_is_test_passed-all_passed.log') 142 142 with open(all_passed_log) as file: 143 143 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 144 144 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) 145 145 self.assertEqual(result.counts.errors, 0) 146 146 147 147 def test_parse_successful_nested_tests_log(self): 148 - all_passed_log = test_data_path('test_is_test_passed-all_passed_nested.log') 148 + all_passed_log = _test_data_path('test_is_test_passed-all_passed_nested.log') 149 149 with open(all_passed_log) as file: 150 150 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 151 151 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) 152 152 self.assertEqual(result.counts.errors, 0) 153 153 154 154 def test_kselftest_nested(self): 155 - kselftest_log = test_data_path('test_is_test_passed-kselftest.log') 155 + kselftest_log = _test_data_path('test_is_test_passed-kselftest.log') 156 156 with open(kselftest_log) as file: 157 157 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 158 158 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) 159 159 self.assertEqual(result.counts.errors, 0) 160 160 161 161 def test_parse_failed_test_log(self): 162 - failed_log = test_data_path('test_is_test_passed-failure.log') 162 + failed_log = _test_data_path('test_is_test_passed-failure.log') 163 163 with open(failed_log) as file: 164 164 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 165 165 self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) 166 166 self.assertEqual(result.counts.errors, 0) 167 167 168 168 def test_parse_failed_nested_tests_log(self): 169 - nested_log = test_data_path('test_is_test_passed-failure-nested.log') 169 + nested_log = _test_data_path('test_is_test_passed-failure-nested.log') 170 170 with open(nested_log) as file: 171 171 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 172 172 self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) ··· 177 177 self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].subtests[0].status) 178 178 179 179 def test_no_header(self): 180 - empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log') 180 + empty_log = _test_data_path('test_is_test_passed-no_tests_run_no_header.log') 181 181 with open(empty_log) as file: 182 182 result = kunit_parser.parse_run_tests( 183 183 kunit_parser.extract_tap_lines(file.readlines()), stdout) ··· 186 186 self.assertEqual(result.counts.errors, 1) 187 187 188 188 def test_missing_test_plan(self): 189 - missing_plan_log = test_data_path('test_is_test_passed-' 189 + missing_plan_log = _test_data_path('test_is_test_passed-' 190 190 'missing_plan.log') 191 191 with open(missing_plan_log) as file: 192 192 result = kunit_parser.parse_run_tests( ··· 197 197 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) 198 198 199 199 def test_no_tests(self): 200 - header_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log') 200 + header_log = _test_data_path('test_is_test_passed-no_tests_run_with_header.log') 201 201 with open(header_log) as file: 202 202 result = kunit_parser.parse_run_tests( 203 203 kunit_parser.extract_tap_lines(file.readlines()), stdout) ··· 206 206 self.assertEqual(result.counts.errors, 1) 207 207 208 208 def test_no_tests_no_plan(self): 209 - no_plan_log = test_data_path('test_is_test_passed-no_tests_no_plan.log') 209 + no_plan_log = _test_data_path('test_is_test_passed-no_tests_no_plan.log') 210 210 with open(no_plan_log) as file: 211 211 result = kunit_parser.parse_run_tests( 212 212 kunit_parser.extract_tap_lines(file.readlines()), stdout) ··· 218 218 219 219 220 220 def test_no_kunit_output(self): 221 - crash_log = test_data_path('test_insufficient_memory.log') 221 + crash_log = _test_data_path('test_insufficient_memory.log') 222 222 print_mock = mock.patch('kunit_printer.Printer.print').start() 223 223 with open(crash_log) as file: 224 224 result = kunit_parser.parse_run_tests( ··· 229 229 self.assertEqual(result.counts.errors, 1) 230 230 231 231 def test_skipped_test(self): 232 - skipped_log = test_data_path('test_skip_tests.log') 232 + skipped_log = _test_data_path('test_skip_tests.log') 233 233 with open(skipped_log) as file: 234 234 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 235 235 ··· 238 238 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=4, skipped=1)) 239 239 240 240 def test_skipped_all_tests(self): 241 - skipped_log = test_data_path('test_skip_all_tests.log') 241 + skipped_log = _test_data_path('test_skip_all_tests.log') 242 242 with open(skipped_log) as file: 243 243 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 244 244 ··· 246 246 self.assertEqual(result.counts, kunit_parser.TestCounts(skipped=5)) 247 247 248 248 def test_ignores_hyphen(self): 249 - hyphen_log = test_data_path('test_strip_hyphen.log') 249 + hyphen_log = _test_data_path('test_strip_hyphen.log') 250 250 with open(hyphen_log) as file: 251 251 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 252 252 ··· 260 260 result.subtests[1].name) 261 261 262 262 def test_ignores_prefix_printk_time(self): 263 - prefix_log = test_data_path('test_config_printk_time.log') 263 + prefix_log = _test_data_path('test_config_printk_time.log') 264 264 with open(prefix_log) as file: 265 265 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 266 266 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) ··· 268 268 self.assertEqual(result.counts.errors, 0) 269 269 270 270 def test_ignores_multiple_prefixes(self): 271 - prefix_log = test_data_path('test_multiple_prefixes.log') 271 + prefix_log = _test_data_path('test_multiple_prefixes.log') 272 272 with open(prefix_log) as file: 273 273 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 274 274 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) ··· 276 276 self.assertEqual(result.counts.errors, 0) 277 277 278 278 def test_prefix_mixed_kernel_output(self): 279 - mixed_prefix_log = test_data_path('test_interrupted_tap_output.log') 279 + mixed_prefix_log = _test_data_path('test_interrupted_tap_output.log') 280 280 with open(mixed_prefix_log) as file: 281 281 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 282 282 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) ··· 284 284 self.assertEqual(result.counts.errors, 0) 285 285 286 286 def test_prefix_poundsign(self): 287 - pound_log = test_data_path('test_pound_sign.log') 287 + pound_log = _test_data_path('test_pound_sign.log') 288 288 with open(pound_log) as file: 289 289 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 290 290 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) ··· 292 292 self.assertEqual(result.counts.errors, 0) 293 293 294 294 def test_kernel_panic_end(self): 295 - panic_log = test_data_path('test_kernel_panic_interrupt.log') 295 + panic_log = _test_data_path('test_kernel_panic_interrupt.log') 296 296 with open(panic_log) as file: 297 297 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 298 298 self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status) ··· 300 300 self.assertGreaterEqual(result.counts.errors, 1) 301 301 302 302 def test_pound_no_prefix(self): 303 - pound_log = test_data_path('test_pound_no_prefix.log') 303 + pound_log = _test_data_path('test_pound_no_prefix.log') 304 304 with open(pound_log) as file: 305 305 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 306 306 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status) ··· 329 329 'Failures: all_failed_suite, some_failed_suite.test2') 330 330 331 331 def test_ktap_format(self): 332 - ktap_log = test_data_path('test_parse_ktap_output.log') 332 + ktap_log = _test_data_path('test_parse_ktap_output.log') 333 333 with open(ktap_log) as file: 334 334 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 335 335 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=3)) ··· 338 338 self.assertEqual('case_2', result.subtests[0].subtests[1].name) 339 339 340 340 def test_parse_subtest_header(self): 341 - ktap_log = test_data_path('test_parse_subtest_header.log') 341 + ktap_log = _test_data_path('test_parse_subtest_header.log') 342 342 with open(ktap_log) as file: 343 343 kunit_parser.parse_run_tests(file.readlines(), stdout) 344 344 self.print_mock.assert_any_call(StrContains('suite (1 subtest)')) 345 345 346 346 def test_parse_attributes(self): 347 - ktap_log = test_data_path('test_parse_attributes.log') 347 + ktap_log = _test_data_path('test_parse_attributes.log') 348 348 with open(ktap_log) as file: 349 349 result = kunit_parser.parse_run_tests(file.readlines(), stdout) 350 350 ··· 566 566 self.addCleanup(mock.patch.stopall) 567 567 568 568 def _json_for(self, log_file): 569 - with open(test_data_path(log_file)) as file: 569 + with open(_test_data_path(log_file)) as file: 570 570 test_result = kunit_parser.parse_run_tests(file, stdout) 571 571 json_obj = kunit_json.get_json_result( 572 572 test=test_result, ··· 607 607 608 608 class KUnitMainTest(unittest.TestCase): 609 609 def setUp(self): 610 - path = test_data_path('test_is_test_passed-all_passed.log') 610 + path = _test_data_path('test_is_test_passed-all_passed.log') 611 611 with open(path) as file: 612 612 all_passed_log = file.readlines() 613 613