Skip to content

Commit 549fbcf

Browse files
test: deduplicate version and report tests
Consolidate three separate version flag tests into a single parametrized test. Merge standalone deprecation warning tests into the existing test_version_for_showing_commitizen_version and test_version_for_showing_commitizen_system_info tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 12584e3 commit 549fbcf

2 files changed

Lines changed: 28 additions & 47 deletions

File tree

tests/commands/test_version_command.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ def test_version_for_showing_project_version(config, capsys):
3131

3232
@pytest.mark.parametrize("project", [True, False])
3333
def test_version_for_showing_commitizen_version(config, capsys, project: bool):
34-
commands.Version(
35-
config,
36-
{"project": project, "commitizen": True},
37-
)()
34+
with pytest.warns(
35+
DeprecationWarning,
36+
match=r"`cz version --commitizen` is deprecated.*Use `cz --version` instead",
37+
):
38+
commands.Version(
39+
config,
40+
{"project": project, "commitizen": True},
41+
)()
3842
captured = capsys.readouterr()
3943
assert f"{__version__}" in captured.out
4044

@@ -63,10 +67,14 @@ def test_version_for_showing_both_versions(config, capsys):
6367

6468

6569
def test_version_for_showing_commitizen_system_info(config, capsys):
66-
commands.Version(
67-
config,
68-
{"report": True},
69-
)()
70+
with pytest.warns(
71+
DeprecationWarning,
72+
match=r"`cz version --report` is deprecated.*Use `cz --report` instead",
73+
):
74+
commands.Version(
75+
config,
76+
{"report": True},
77+
)()
7078
captured = capsys.readouterr()
7179
assert f"Commitizen Version: {__version__}" in captured.out
7280
assert f"Python Version: {sys.version}" in captured.out
@@ -296,23 +304,3 @@ def test_version_no_arguments_shows_commitizen_version(config, capsys):
296304
commands.Version(config, {})()
297305
captured = capsys.readouterr()
298306
assert captured.out.strip() == __version__
299-
300-
301-
def test_version_report_emits_deprecation_warning(config, capsys):
302-
with pytest.warns(
303-
DeprecationWarning,
304-
match=r"`cz version --report` is deprecated.*Use `cz --report` instead",
305-
):
306-
commands.Version(config, {"report": True})()
307-
captured = capsys.readouterr()
308-
assert f"Commitizen Version: {__version__}" in captured.out
309-
310-
311-
def test_version_commitizen_emits_deprecation_warning(config, capsys):
312-
with pytest.warns(
313-
DeprecationWarning,
314-
match=r"`cz version --commitizen` is deprecated.*Use `cz --version` instead",
315-
):
316-
commands.Version(config, {"commitizen": True})()
317-
captured = capsys.readouterr()
318-
assert __version__ in captured.out

tests/test_cli.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,19 @@ def test_cz_with_arg_but_without_command(util: UtilFixture):
5656
assert "Command is required" in str(excinfo.value)
5757

5858

59-
def test_cz_with_version_arg(util: UtilFixture, capsys):
60-
"""Test that cz shows the version when --version is used."""
61-
with pytest.raises(ExpectedExit):
62-
util.run_cli("--version")
63-
out, _ = capsys.readouterr()
64-
assert __version__ in out
65-
66-
67-
def test_cz_with_version_short_arg(util: UtilFixture, capsys):
68-
"""Test that cz shows the version when -v is used."""
69-
with pytest.raises(ExpectedExit):
70-
util.run_cli("-v")
71-
out, _ = capsys.readouterr()
72-
assert __version__ in out
73-
74-
75-
def test_cz_version_flag_takes_precedence_over_subcommand(util: UtilFixture, capsys):
76-
"""Test that --version takes precedence even when a subcommand is given."""
59+
@pytest.mark.parametrize(
60+
"args",
61+
[
62+
("--version",),
63+
("-v",),
64+
("--version", "bump"),
65+
],
66+
ids=["long-flag", "short-flag", "precedence-over-subcommand"],
67+
)
68+
def test_cz_with_version_arg(util: UtilFixture, capsys, args):
69+
"""Test that cz --version / -v shows the version and takes precedence."""
7770
with pytest.raises(ExpectedExit):
78-
util.run_cli("--version", "bump")
71+
util.run_cli(*args)
7972
out, _ = capsys.readouterr()
8073
assert __version__ in out
8174

0 commit comments

Comments
 (0)