Skip to content

Commit 0794acd

Browse files
committed
fix(cli,bump): remove ExpectedExit to fix exception raised issue on expected command execution
1 parent aa82b98 commit 0794acd

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

commitizen/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from commitizen.exceptions import (
1717
CommitizenException,
1818
ExitCode,
19-
ExpectedExit,
2019
InvalidCommandArgumentError,
2120
NoCommandFoundError,
2221
)
@@ -634,7 +633,7 @@ def main() -> None:
634633
# Show help if no arg provided
635634
if len(sys.argv) == 1:
636635
parser.print_help(sys.stderr)
637-
raise ExpectedExit()
636+
return
638637

639638
# This is for the command required constraint in 2.0
640639
try:

commitizen/commands/bump.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
BumpCommitFailedError,
1515
BumpTagFailedError,
1616
DryRunExit,
17-
ExpectedExit,
1817
InvalidManualVersion,
1918
NoCommitsFoundError,
2019
NoneIncrementExit,
@@ -367,7 +366,7 @@ def __call__(self) -> None:
367366
)
368367

369368
if self.arguments["files_only"]:
370-
raise ExpectedExit()
369+
return
371370

372371
# FIXME: check if any changes have been staged
373372
git.add(*updated_files)

tests/commands/test_bump_command.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
CurrentVersionNotFoundError,
1919
DryRunExit,
2020
ExitCode,
21-
ExpectedExit,
2221
InvalidManualVersion,
2322
NoCommitsFoundError,
2423
NoneIncrementExit,
@@ -469,8 +468,7 @@ def test_bump_files_only(tmp_commitizen_project, util: UtilFixture):
469468
assert tag_exists is True
470469

471470
util.create_file_and_commit("feat: another new feature")
472-
with pytest.raises(ExpectedExit):
473-
util.run_cli("bump", "--yes", "--files-only")
471+
util.run_cli("bump", "--yes", "--files-only")
474472

475473
tag_exists = git.tag_exist("0.3.0")
476474
assert tag_exists is False
@@ -519,8 +517,7 @@ def test_bump_dry_run(util: UtilFixture, capsys):
519517
def test_bump_in_non_git_project(tmpdir, config, util: UtilFixture):
520518
with tmpdir.as_cwd():
521519
with pytest.raises(NotAGitProjectError):
522-
with pytest.raises(ExpectedExit):
523-
util.run_cli("bump", "--yes")
520+
util.run_cli("bump", "--yes")
524521

525522

526523
def test_none_increment_exit_should_be_a_class():
@@ -1266,8 +1263,7 @@ def test_bump_changelog_contains_increment_only(
12661263
# Add a commit and create the incremental changelog to v3.0.0
12671264
# it should only include v3 changes
12681265
util.create_file_and_commit("feat(next)!: next version")
1269-
with pytest.raises(ExpectedExit):
1270-
util.run_cli("bump", "--yes", "--files-only", "--changelog-to-stdout")
1266+
util.run_cli("bump", "--yes", "--files-only", "--changelog-to-stdout")
12711267
out, _ = capsys.readouterr()
12721268

12731269
assert "3.0.0" in out

tests/test_cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from commitizen import cli
1111
from commitizen.exceptions import (
1212
ConfigFileNotFound,
13-
ExpectedExit,
1413
InvalidCommandArgumentError,
1514
NoCommandFoundError,
1615
NotAGitProjectError,
@@ -19,10 +18,9 @@
1918

2019

2120
def test_sysexit_no_argv(util: UtilFixture, capsys):
22-
with pytest.raises(ExpectedExit):
23-
util.run_cli()
24-
out, _ = capsys.readouterr()
25-
assert out.startswith("usage")
21+
util.run_cli()
22+
_, err = capsys.readouterr()
23+
assert err.startswith("usage")
2624

2725

2826
def test_cz_config_file_without_correct_file_path(util: UtilFixture, capsys):

0 commit comments

Comments
 (0)