summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2021-08-05 06:48:24 -0700
committerGitHub <noreply@github.com>2021-08-05 06:48:24 -0700
commit5d759e0ab383136f9869cdb5e14f00c78b38a9c9 (patch)
treed1962eef8ed26f8d001649e4af5cefd290fdff9c /tests
parent68e65ee2bf3e057a99d1192cc256cc2cb2a12203 (diff)
parent2cc7244becaa7381d6b5b0a7404490d5210c833a (diff)
downloadclick-5d759e0ab383136f9869cdb5e14f00c78b38a9c9.tar.gz
Merge pull request #1998 from MLH-Fellowship/1971-hide-defaults
Hide single option boolean flags in "help" when the default is False
Diffstat (limited to 'tests')
-rw-r--r--tests/test_formatting.py3
-rw-r--r--tests/test_options.py31
2 files changed, 28 insertions, 6 deletions
diff --git a/tests/test_formatting.py b/tests/test_formatting.py
index f957e01..1cbf32b 100644
--- a/tests/test_formatting.py
+++ b/tests/test_formatting.py
@@ -322,12 +322,13 @@ def test_global_show_default(runner):
pass
result = runner.invoke(cli, ["--help"])
+ # the default to "--help" is not shown because it is False
assert result.output.splitlines() == [
"Usage: cli [OPTIONS]",
"",
"Options:",
" -f TEXT Output file name [default: out.txt]",
- " --help Show this message and exit. [default: False]",
+ " --help Show this message and exit.",
]
diff --git a/tests/test_options.py b/tests/test_options.py
index 53179e8..efdda48 100644
--- a/tests/test_options.py
+++ b/tests/test_options.py
@@ -700,16 +700,37 @@ def test_show_default_boolean_flag_name(runner, default, expect):
assert f"[default: {expect}]" in message
-def test_show_default_boolean_flag_value(runner):
- """When a boolean flag only has one opt, it will show the default
- value, not the opt name.
+def test_show_true_default_boolean_flag_value(runner):
+ """When a boolean flag only has one opt and its default is True,
+ it will show the default value, not the opt name.
"""
opt = click.Option(
- ("--cache",), is_flag=True, show_default=True, help="Enable the cache."
+ ("--cache",),
+ is_flag=True,
+ show_default=True,
+ default=True,
+ help="Enable the cache.",
+ )
+ ctx = click.Context(click.Command("test"))
+ message = opt.get_help_record(ctx)[1]
+ assert "[default: True]" in message
+
+
+@pytest.mark.parametrize("default", [False, None])
+def test_hide_false_default_boolean_flag_value(runner, default):
+ """When a boolean flag only has one opt and its default is False or
+ None, it will not show the default
+ """
+ opt = click.Option(
+ ("--cache",),
+ is_flag=True,
+ show_default=True,
+ default=default,
+ help="Enable the cache.",
)
ctx = click.Context(click.Command("test"))
message = opt.get_help_record(ctx)[1]
- assert "[default: False]" in message
+ assert "[default: " not in message
def test_show_default_string(runner):