Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set exit code to 0 or 1 based on results #683

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion precli/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ def main():
if args.gist is True:
create_gist(file, renderer)

sys.exit(0)
if run.results:
sys.exit(1)
else:
sys.exit(0)


if __name__ == "__main__":
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def test_main_recursive_flag(self, monkeypatch):
main.main()
assert excinfo.value.code == 0

def test_main_exit_code_0(self, monkeypatch):
temp_dir = tempfile.mkdtemp()
monkeypatch.setattr("sys.argv", ["precli", temp_dir])
with pytest.raises(SystemExit) as excinfo:
main.main()
assert excinfo.value.code == 0

def test_main_version(self, monkeypatch, capsys):
monkeypatch.setattr("sys.argv", ["precli", "--version"])
with pytest.raises(SystemExit) as excinfo:
Expand Down