diff --git a/ament_tools/verbs/test_pkg/cli.py b/ament_tools/verbs/test_pkg/cli.py index ac8ecb1..188f3f9 100644 --- a/ament_tools/verbs/test_pkg/cli.py +++ b/ament_tools/verbs/test_pkg/cli.py @@ -47,6 +47,12 @@ def prepare_arguments(parser, args, skip_build_pkg_arguments=False): type=int, default=0, metavar='N', help='Rerun failing tests up to N times', ) + parser.add_argument( + '--ignore-return-codes', + action='store_true', + default=False, + help='Ignore return codes from testing packages', + ) return parser @@ -75,18 +81,21 @@ def main(opts): return try: handle_build_action(on_test_ret, context) - except SystemExit: + except SystemExit as e: # check if tests should be rerun if opts.retest_until_pass > context.test_iteration: context.test_iteration += 1 print("+++ Testing '%s' again (retry #%d of %d)" % (pkg_name, context.test_iteration, opts.retest_until_pass)) continue - # there is no way to distinguish why the test returned non zero - # the test invocation itself could have failed: - # return e.code - # but it could have also run successful and only failed some tests: - return + # Automated systems can use --ignore-return-codes to allow them to react to + # a failure to *run* a test but not a failure generated by a test that ran as + # intended. Otherwise, we'll combine the two cases to help users to notice + # when anything went wrong during a test run. + if opts.ignore_return_codes: + return + else: + return e.code # check if tests should be rerun if opts.retest_until_fail > context.test_iteration: context.test_iteration += 1