Skip to content

Commit 182a58f

Browse files
committed
test(cli): add test cast for commitizen_excepthook
1 parent da79d1e commit 182a58f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/test_cli.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from commitizen import cli
66
from commitizen.__version__ import __version__
7-
from commitizen.exceptions import ExpectedExit, NoCommandFoundError
7+
from commitizen.exceptions import ExpectedExit, NoCommandFoundError, NotAGitProjectError
88

99

1010
def test_sysexit_no_argv(mocker, capsys):
@@ -75,3 +75,22 @@ def test_arg_debug(mocker):
7575
mocker.patch.object(sys, "argv", testargs)
7676
cli.main()
7777
assert sys.excepthook.keywords.get("debug") is True
78+
79+
80+
def test_commitizen_excepthook(capsys):
81+
with pytest.raises(SystemExit) as excinfo:
82+
cli.commitizen_excepthook(NotAGitProjectError, NotAGitProjectError(), "")
83+
84+
assert excinfo.type == SystemExit
85+
assert excinfo.value.code == NotAGitProjectError.exit_code
86+
87+
88+
def test_commitizen_debug_excepthook(capsys):
89+
with pytest.raises(SystemExit) as excinfo:
90+
cli.commitizen_excepthook(
91+
NotAGitProjectError, NotAGitProjectError(), "", debug=True,
92+
)
93+
94+
assert excinfo.type == SystemExit
95+
assert excinfo.value.code == NotAGitProjectError.exit_code
96+
assert "NotAGitProjectError" in str(excinfo.traceback[0])

0 commit comments

Comments
 (0)