Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e6b5e8b

Browse files
crai0Lee-W
authored andcommitted
test(commit): add test for --no-retry flag
1 parent 0c95c16 commit e6b5e8b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎tests/commands/test_commit_command.py‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,54 @@ def test_commit_retry_after_failure_works(config, mocker: MockFixture):
157157
assert not os.path.isfile(temp_file)
158158

159159

160+
@pytest.mark.usefixtures("staging_is_clean")
161+
def test_commit_retry_after_failure_with_no_retry_works(config, mocker: MockFixture):
162+
prompt_mock = mocker.patch("questionary.prompt")
163+
prompt_mock.return_value = {
164+
"prefix": "feat",
165+
"subject": "user created",
166+
"scope": "",
167+
"is_breaking_change": False,
168+
"body": "closes #21",
169+
"footer": "",
170+
}
171+
172+
commit_mock = mocker.patch("commitizen.git.commit")
173+
commit_mock.return_value = cmd.Command("", "error", b"", b"", 9)
174+
error_mock = mocker.patch("commitizen.out.error")
175+
176+
with pytest.raises(CommitError):
177+
commit_cmd = commands.Commit(config, {})
178+
temp_file = commit_cmd.temp_file
179+
commit_cmd()
180+
181+
prompt_mock.assert_called_once()
182+
error_mock.assert_called_once()
183+
assert os.path.isfile(temp_file)
184+
185+
# provide different prompt to test that --no-retry ignore backup file
186+
prompt_mock = mocker.patch("questionary.prompt")
187+
prompt_mock.return_value = {
188+
"prefix": "feat",
189+
"subject": "user created",
190+
"scope": "",
191+
"is_breaking_change": False,
192+
"body": "closes #22",
193+
"footer": "",
194+
}
195+
196+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
197+
success_mock = mocker.patch("commitizen.out.success")
198+
199+
config.settings["retry_after_failure"] = True
200+
commands.Commit(config, {"no_retry": True})()
201+
202+
commit_mock.assert_called_with("feat: user created\n\ncloses #22", args="")
203+
prompt_mock.assert_called()
204+
success_mock.assert_called_once()
205+
assert not os.path.isfile(temp_file)
206+
207+
160208
@pytest.mark.usefixtures("staging_is_clean")
161209
def test_commit_command_with_dry_run_option(config, mocker: MockFixture):
162210
prompt_mock = mocker = mocker.patch("questionary.prompt")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /