diff --git a/b2/_internal/_cli/autocomplete_install.py b/b2/_internal/_cli/autocomplete_install.py index f0e6bb1f..ade16130 100644 --- a/b2/_internal/_cli/autocomplete_install.py +++ b/b2/_internal/_cli/autocomplete_install.py @@ -193,22 +193,25 @@ def is_enabled(self) -> bool: That alone cannot be used, since fish tends to always propose completions (e.g. suggesting similarly named filenames). """ + environ = os.environ.copy() + environ.setdefault("TERM", "xterm") # TERM has to be set for fish to load completions return _silent_success_run( [ self.shell_exec, '-i', '-c', f'string length -q -- (complete -C{quote(f"{self.prog} ")} >/dev/null && complete -c {quote(self.prog)})' - ] + ], + env=environ, ) -def _silent_success_run(cmd: list[str], timeout: int | None = 60) -> bool: - # start_new_session prevents `zsh -i` interaction with parent terminal under pytest-xdist +def _silent_success_run(cmd: list[str], timeout: int | None = 60, env: dict | None = None) -> bool: p = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL, - start_new_session=True, + start_new_session=True, # prevents `zsh -i` messing with parent tty under pytest-xdist + env=env, ) try: diff --git a/test/unit/conftest.py b/test/unit/conftest.py index 2aebc15c..9e40d938 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -53,6 +53,8 @@ def env(homedir, monkeypatch): """Get ENV for running b2 command from shell level.""" monkeypatch.setenv("HOME", str(homedir)) monkeypatch.setenv("SHELL", "/bin/bash") # fix for running under github actions + if "TERM" not in os.environ: + monkeypatch.setenv("TERM", "xterm") yield os.environ diff --git a/test/unit/console_tool/test_install_autocomplete.py b/test/unit/console_tool/test_install_autocomplete.py index 3f3caa3d..bbf3fd6c 100644 --- a/test/unit/console_tool/test_install_autocomplete.py +++ b/test/unit/console_tool/test_install_autocomplete.py @@ -37,9 +37,6 @@ def test_install_autocomplete(b2_cli, env, shell, monkeypatch): expected_part_of_stdout=f"Autocomplete successfully installed for {shell}", ) - if shell == "fish": # no idea how to test fish autocompletion (does not seem to work with dummy terminal) - return - with pexpect_shell(shell_bin, env=env) as pshell: pshell.send("b2 \t\t") pshell.expect_exact(["authorize-account", "download-file", "get-bucket"], timeout=30)