@@ -86,7 +86,10 @@ def _check_cwd() -> bool:
8686
8787def _load (skip_lint : bool = False ) -> Tuple [List [DefaultMunch ], int ]:
8888 """Loads definition files (all the YAML files in a given directory)
89- and extracts the definitions that contain at least one test.
89+ and extracts the definitions that contain at least one test. The
90+ definition blocks for those that have tests (ignored or otherwise)
91+ are returned along with a count of the number of tests found
92+ (ignored or otherwise).
9093
9194 If there was a problem loading the files an empty list and
9295 -ve count is returned.
@@ -225,30 +228,42 @@ def _check(t_compose: Compose,
225228def _test (args : argparse .Namespace ,
226229 collection : str ,
227230 job : str ,
228- job_definition : DefaultMunch ) -> bool :
229- """Runs test for a specific Job definition returning True on success.
231+ job_definition : DefaultMunch ) -> Tuple [int , int , int ]:
232+ """Runs the tests for a specific Job definition returning True on success.
233+ If an individual test is marked as 'ignored' it will not be processed,
234+ and will not be counted.
235+
236+ The function returns a tuple containing the count of the number of tests
237+ that passed, were ignored and those that failed.
230238 """
231239 assert job_definition
232240 assert isinstance (job_definition , DefaultMunch )
233241
234242 # The test status, assume success
235- test_status : bool = True
243+ tests_passed : int = 0
244+ tests_ignored : int = 0
245+ tests_failed : int = 0
236246
237247 job_image : str = f'{ job_definition .image .name } :{ job_definition .image .tag } '
238248 job_project_directory : str = job_definition .image ['project-directory' ]
239249 job_working_directory : str = job_definition .image ['working-directory' ]
240250
241251 for job_test_name in job_definition .tests :
242252
243- test_status = True
244-
245253 # If a job test has been named,
246- # skip this test if it doesn't match
254+ # skip this test if it doesn't match.
255+ # We do not include this test in the count.
247256 if args .test and not args .test == job_test_name :
248257 continue
249258
250259 _print_test_banner (collection , job , job_test_name )
251260
261+ # Does the test have an 'ignore' declaration?
262+ if 'ignore' in job_definition .tests [job_test_name ]:
263+ print ('W Ignoring test (found "ignore")' )
264+ tests_ignored += 1
265+ continue
266+
252267 # Render the command for this test.
253268 # First extract the variables and values from 'options'
254269 # and then 'inputs'...
@@ -275,6 +290,9 @@ def _test(args: argparse.Namespace,
275290 print ('! FAILURE' )
276291 print ('! Failed to render command' )
277292 print (f'! error={ decoded_command } ' )
293+ # Record but do no further processing
294+ tests_failed += 1
295+ test_status = False
278296
279297 # The command must not contain new-lines.
280298 # So split then join the command.
@@ -343,11 +361,17 @@ def _test(args: argparse.Namespace,
343361 if test_status and not args .keep_results :
344362 t_compose .delete ()
345363
364+ # Count?
365+ if test_status :
366+ tests_passed += 1
367+ else :
368+ tests_failed += 1
369+
346370 # Told to stop on first failure?
347371 if not test_status and args .exit_on_failure :
348372 break
349373
350- return test_status
374+ return tests_passed , tests_ignored , tests_failed
351375
352376
353377def _wipe () -> None :
@@ -428,7 +452,8 @@ def main() -> None:
428452 arg_parser .error ('--job requires --collection' )
429453
430454 # Args are OK if we get here.
431- test_fail_count : int = 0
455+ total_fail_count : int = 0
456+ total_ignore_count : int = 0
432457
433458 # Check CWD
434459 if not _check_cwd ():
@@ -476,29 +501,38 @@ def main() -> None:
476501 continue
477502
478503 if job_definition .jobs [job_name ].tests :
479- if not _test (args ,
480- collection ,
481- job_name ,
482- job_definition .jobs [job_name ]):
483- test_fail_count += 1
484- if args .exit_on_failure :
485- break
486- if test_fail_count and args .exit_on_failure :
504+ num_passed , num_ignored , num_failed = \
505+ _test (args ,
506+ collection ,
507+ job_name ,
508+ job_definition .jobs [job_name ])
509+ total_ignore_count += num_ignored
510+ total_fail_count += num_failed
511+
512+ # Break out of this loop if told to stop on failures
513+ if num_failed > 0 and args .exit_on_failure :
514+ break
515+
516+ # Break out of this loop if told to stop on failures
517+ if num_failed > 0 and args .exit_on_failure :
487518 break
488519
489520 # Success or failure?
490521 # It's an error to find no tests.
491522 print (' ---' )
492- num_tests_passed : int = num_tests - test_fail_count
523+ num_tests_passed : int = num_tests - total_fail_count - total_ignore_count
493524 dry_run : str = '[DRY RUN]' if args .dry_run else ''
494- if test_fail_count :
525+ if total_fail_count :
495526 arg_parser .error ('Done (FAILURE)'
496527 f' passed={ num_tests_passed } '
497- f' failed={ test_fail_count } '
528+ f' ignored={ total_ignore_count } '
529+ f' failed={ total_fail_count } '
498530 f' { dry_run } ' )
499531 elif num_tests_passed == 0 :
500532 arg_parser .error ('Done (FAILURE)'
501533 f' passed={ num_tests_passed } '
534+ f' ignored={ total_ignore_count } '
535+ f' failed=0'
502536 f' (at least one test must pass) { dry_run } ' )
503537 else :
504538 print (f'Done (OK) passed={ num_tests_passed } { dry_run } ' )
0 commit comments