Skip to content
Open
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
12 changes: 5 additions & 7 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,11 @@ def test_none_increment_should_not_call_git_tag_and_error_code_is_not_zero(
dummy_value = git.tag("0.0.2")
git.tag = MagicMock(return_value=dummy_value)

with pytest.raises(NoneIncrementExit):
try:
cli.main()
except NoneIncrementExit as e:
git.tag.assert_not_called()
assert e.exit_code == ExitCode.NO_INCREMENT
raise e
with pytest.raises(NoneIncrementExit) as e:
cli.main()

git.tag.assert_not_called()
assert e.value.exit_code == ExitCode.NO_INCREMENT

# restore pop stashed
git.tag = stashed_git_tag
Expand Down
7 changes: 4 additions & 3 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ def test_changelog_hook(mocker: MockFixture, config: BaseConfig, dry_run: bool):
config, {"unreleased_version": None, "incremental": True, "dry_run": dry_run}
)
mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock)
try:
if dry_run:
with pytest.raises(DryRunExit):
changelog()
else:
changelog()
except DryRunExit:
pass

full_changelog = (
"## Unreleased\n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"
Expand Down
14 changes: 6 additions & 8 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import pytest
from pytest_mock import MockFixture

from commitizen import cmd, exceptions, git
from commitizen import cmd, git
from commitizen.exceptions import GitCommandError
from tests.utils import (
FakeCommand,
create_branch,
Expand Down Expand Up @@ -111,11 +112,8 @@ def test_git_message_with_empty_body():
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_get_log_as_str_list_empty():
"""ensure an exception or empty list in an empty project"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why there are more than one possible behavior in the original test code. That's strange.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a look at the history. Looks like it varies based on the git version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to take a look at which git version changed this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

try:
gitlog = git._get_log_as_str_list(start=None, end="HEAD", args="")
except exceptions.GitCommandError:
return
assert len(gitlog) == 0, "list should be empty if no assert"
with pytest.raises(GitCommandError):
git._get_log_as_str_list(start=None, end="HEAD", args="")


@pytest.mark.usefixtures("tmp_commitizen_project")
Expand Down Expand Up @@ -409,7 +407,7 @@ def test_get_filenames_in_commit_error(mocker: MockFixture):
"commitizen.cmd.run",
return_value=FakeCommand(out="", err="fatal: bad object HEAD", return_code=1),
)
with pytest.raises(exceptions.GitCommandError) as excinfo:
with pytest.raises(GitCommandError) as excinfo:
git.get_filenames_in_commit()
assert str(excinfo.value) == "fatal: bad object HEAD"

Expand Down Expand Up @@ -497,5 +495,5 @@ def test_get_default_branch_error(mocker: MockFixture):
return_code=1,
),
)
with pytest.raises(exceptions.GitCommandError):
with pytest.raises(GitCommandError):
git.get_default_branch()