diff --git a/olive/cli/run_pass.py b/olive/cli/run_pass.py index 3ed269185..18f2076b5 100644 --- a/olive/cli/run_pass.py +++ b/olive/cli/run_pass.py @@ -198,6 +198,7 @@ def _list_passes(self): except Exception as e: print(f"Error loading pass configurations: {e}") print("Unable to list available passes.") + raise SystemExit(1) from e # Template configuration for the one command diff --git a/test/cli/test_run_pass_exit_status.py b/test/cli/test_run_pass_exit_status.py new file mode 100644 index 000000000..7cb7c5167 --- /dev/null +++ b/test/cli/test_run_pass_exit_status.py @@ -0,0 +1,26 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------------------- +from argparse import ArgumentParser +from unittest.mock import patch + +import pytest + +from olive.cli.run_pass import RunPassCommand + + +def test_list_passes_failure_exits_nonzero(): + parser = ArgumentParser() + sub_parsers = parser.add_subparsers() + RunPassCommand.register_subcommand(sub_parsers) + args = parser.parse_args(["run-pass", "--list-passes"]) + command = RunPassCommand(parser, args) + + config_error = patch( + "olive.package_config.OlivePackageConfig.load_default_config", side_effect=RuntimeError("broken config") + ) + with config_error, pytest.raises(SystemExit) as exc_info: + command.run() + + assert exc_info.value.code == 1