-
-
Notifications
You must be signed in to change notification settings - Fork 305
test(commands): centralize all --help tests in a file to dedup code #1726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import sys | ||
|
|
||
| import pytest | ||
| from pytest_mock import MockFixture | ||
|
|
||
| from commitizen import cli | ||
| from commitizen.commands import Example, Info, ListCz, Schema | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| sys.version_info < (3, 13), | ||
| reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13", | ||
| ) | ||
| @pytest.mark.parametrize( | ||
| "command", | ||
| [ | ||
| "bump", | ||
| "changelog", | ||
| "check", | ||
| "commit", | ||
| "example", | ||
| "info", | ||
| "init", | ||
| "ls", | ||
| "schema", | ||
| "version", | ||
| ], | ||
| ) | ||
| def test_command_shows_description_when_use_help_option( | ||
| mocker: MockFixture, | ||
| capsys, | ||
| file_regression, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| command: str, | ||
| ): | ||
| """Test that the command shows the description when the help option is used. | ||
|
|
||
| Note: If the command description changes, please run `pytest tests/commands/test_common_command.py --regen-all` to regenerate the test files. | ||
| """ | ||
| # Force consistent terminal output | ||
| monkeypatch.setenv("COLUMNS", "80") | ||
| monkeypatch.setenv("TERM", "dumb") | ||
| monkeypatch.setenv("LC_ALL", "C") | ||
| monkeypatch.setenv("LANG", "C") | ||
| monkeypatch.setenv("NO_COLOR", "1") | ||
| monkeypatch.setenv("PAGER", "cat") | ||
|
Comment on lines
+41
to
+46
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from AI output. I know COLUMNS is necessary, but not sure for the rest
Comment on lines
+40
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could be a fixture like
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do in another PR |
||
|
|
||
| testargs = ["cz", command, "--help"] | ||
| mocker.patch.object(sys, "argv", testargs) | ||
| with pytest.raises(SystemExit): | ||
| cli.main() | ||
|
|
||
| out, _ = capsys.readouterr() | ||
| file_regression.check(out, extension=".txt") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "command", | ||
| [ | ||
| Example, | ||
| Info, | ||
| ListCz, | ||
| Schema, | ||
| ], | ||
| ) | ||
| def test_simple_command_call_once(config, mocker: MockFixture, command): | ||
| write_mock = mocker.patch("commitizen.out.write") | ||
| command(config)() | ||
| write_mock.assert_called_once() | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we have different snapshots for Python <3.13 and >=3.13 ?
It seems weird to have some tests skipped for some Python version for things that are existing on those Python versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I will check how to do it later and will do in another PR.