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 2532003

Browse files
crai0Lee-W
authored andcommitted
test(commit): add tests for retry_after_failure config option and --no-retry flag
1 parent 3212eaa commit 2532003

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

‎tests/commands/test_commit_command.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,69 @@ def test_commit_retry_works(config, mocker: MockFixture):
9494
assert not os.path.isfile(temp_file)
9595

9696

97+
@pytest.mark.usefixtures("staging_is_clean")
98+
def test_commit_retry_after_failure_no_backup(config, mocker: MockFixture):
99+
prompt_mock = mocker.patch("questionary.prompt")
100+
prompt_mock.return_value = {
101+
"prefix": "feat",
102+
"subject": "user created",
103+
"scope": "",
104+
"is_breaking_change": False,
105+
"body": "closes #21",
106+
"footer": "",
107+
}
108+
109+
commit_mock = mocker.patch("commitizen.git.commit")
110+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
111+
success_mock = mocker.patch("commitizen.out.success")
112+
113+
config.settings["retry_after_failure"] = True
114+
commands.Commit(config, {})()
115+
116+
commit_mock.assert_called_with("feat: user created\n\ncloses #21", args="")
117+
prompt_mock.assert_called_once()
118+
success_mock.assert_called_once()
119+
120+
121+
@pytest.mark.usefixtures("staging_is_clean")
122+
def test_commit_retry_after_failure_works(config, mocker: MockFixture):
123+
prompt_mock = mocker.patch("questionary.prompt")
124+
prompt_mock.return_value = {
125+
"prefix": "feat",
126+
"subject": "user created",
127+
"scope": "",
128+
"is_breaking_change": False,
129+
"body": "closes #21",
130+
"footer": "",
131+
}
132+
133+
commit_mock = mocker.patch("commitizen.git.commit")
134+
commit_mock.return_value = cmd.Command("", "error", b"", b"", 9)
135+
error_mock = mocker.patch("commitizen.out.error")
136+
137+
with pytest.raises(CommitError):
138+
commit_cmd = commands.Commit(config, {})
139+
temp_file = commit_cmd.temp_file
140+
commit_cmd()
141+
142+
prompt_mock.assert_called_once()
143+
error_mock.assert_called_once()
144+
assert os.path.isfile(temp_file)
145+
146+
# Previous commit failed, so retry should pick up the backup commit
147+
# commit_mock = mocker.patch("commitizen.git.commit")
148+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
149+
success_mock = mocker.patch("commitizen.out.success")
150+
151+
config.settings["retry_after_failure"] = True
152+
commands.Commit(config, {})()
153+
154+
commit_mock.assert_called_with("feat: user created\n\ncloses #21", args="")
155+
prompt_mock.assert_called_once()
156+
success_mock.assert_called_once()
157+
assert not os.path.isfile(temp_file)
158+
159+
97160
@pytest.mark.usefixtures("staging_is_clean")
98161
def test_commit_command_with_dry_run_option(config, mocker: MockFixture):
99162
prompt_mock = mocker = mocker.patch("questionary.prompt")

‎tests/test_conf.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"version_scheme": None,
5353
"tag_format": "$version",
5454
"bump_message": None,
55+
"retry_after_failure": False,
5556
"allow_abort": False,
5657
"allowed_prefixes": ["Merge", "Revert", "Pull request", "fixup!", "squash!"],
5758
"version_files": ["commitizen/__version__.py", "pyproject.toml"],
@@ -80,6 +81,7 @@
8081
"version_scheme": None,
8182
"tag_format": "$version",
8283
"bump_message": None,
84+
"retry_after_failure": False,
8385
"allow_abort": False,
8486
"allowed_prefixes": ["Merge", "Revert", "Pull request", "fixup!", "squash!"],
8587
"version_files": ["commitizen/__version__.py", "pyproject.toml"],

0 commit comments

Comments
(0)

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