diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index ef68dff46..e3796f7bc 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -259,24 +259,26 @@ def get_completion_source(shell): completion_source = shell_source # BashComplete only supports versions >= 4.4 if shell == "bash": - output = run(["bash", "--version"], stdout=PIPE) - match = re.search(r"\d\.\d\.\d", output.stdout.decode()) - if match: - bash_version = match.group().split(".") - if ( - bash_version[0] < "4" - or bash_version[0] == "4" - and bash_version[1] < "4" - ): - raise Exception( - "Shell completion is not supported" - "for bash versions older than 4.4" - ) + if bash_version_not_usable(): + raise Exception( + "Shell completion is not supported" + "for bash versions older than 4.4" + ) break return completion_source +def bash_version_not_usable(): + output = run(["bash", "--version"], stdout=PIPE) + match = re.search(r"\d\.\d\.\d", output.stdout.decode()) + if match: + bash_version = match.group().split(".") + if bash_version[0] < "4" or bash_version[0] == "4" and bash_version[1] < "4": + return True + return False + + def is_incomplete_argument(current_params, cmd_param): """ :param current_params: the current params and values for this diff --git a/tests/test_shellcomplete.py b/tests/test_shellcomplete.py index 0332b0427..40747d563 100644 --- a/tests/test_shellcomplete.py +++ b/tests/test_shellcomplete.py @@ -6,6 +6,7 @@ from click.core import Command from click.core import MultiCommand from click.core import Parameter +from click.shell_completion import bash_version_not_usable from click.shell_completion import get_completion_source from click.shell_completion import resolve_ctx from click.shell_completion import resolve_partial_value @@ -13,6 +14,10 @@ # TODO: change ``do_completion`` interface so it can be directly # tested rather than having to create these helper functions +pytestmark = pytest.mark.skipif( + bash_version_not_usable(), reason="Autocomplete not supported on bash < 4.4" +) + def create_cmpl_obj(cli, shell): prog_name = cli.name