diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index bfbcb41781..c7b3c47d18 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -72,7 +72,7 @@ jobs: env: # Number of expected test passes, safety measure for accidental skip of # tests. Update value if you add/remove tests. - PYTEST_REQPASS: 874 + PYTEST_REQPASS: 875 steps: - uses: actions/checkout@v4 with: diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index c79e31e07b..c73e4c5ce3 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -292,6 +292,11 @@ def get_version_warning() -> str: # 0.1dev1 is special fallback version if __version__ == "0.1.dev1": # pragma: no cover return "" + pip = guess_install_method() + # If we do not know how to upgrade, we do not want to show any warnings + # about version. + if not pip: + return "" msg = "" data = {} @@ -332,9 +337,6 @@ def get_version_warning() -> str: msg = "[dim]You are using a pre-release version of ansible-lint.[/]" elif current_version < new_version: msg = f"""[warning]A new release of ansible-lint is available: [red]{current_version}[/] → [green][link={html_url}]{new_version}[/][/][/]""" - - pip = guess_install_method() - if pip: - msg += f" Upgrade by running: [info]{pip}[/]" + msg += f" Upgrade by running: [info]{pip}[/]" return msg diff --git a/test/test_main.py b/test/test_main.py index e7839b45c6..e7258eed1d 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -86,6 +86,12 @@ def test_get_version_warning( assert len(msg.split("\n")) == outlen +def test_get_version_warning_no_pip(mocker: MockerFixture) -> None: + """Test that we do not display any message if install method is not pip.""" + mocker.patch("ansiblelint.config.guess_install_method", return_value="") + assert get_version_warning() == "" + + @pytest.mark.parametrize( ("lintable"), (