From ef4a49fac5bf08d196e5a266a8ba86c073975daa Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 12 May 2023 09:37:55 +0100 Subject: [PATCH] Hide warning about unique filter originating from core (#3436) Co-authored-by: Erwin Janssen --- .github/workflows/tox.yml | 2 +- .projects/ansible-compat | 2 +- .../bug-core-warning-unique-filter-fallback.yml | 11 +++++++++++ src/ansiblelint/runner.py | 10 ++++++++++ test/test_examples.py | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 examples/playbooks/bug-core-warning-unique-filter-fallback.yml diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 2bb376e9b8..e06c5e8320 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -59,7 +59,7 @@ jobs: WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY # Number of expected test passes, safety measure for accidental skip of # tests. Update value if you add/remove tests. - PYTEST_REQPASS: 796 + PYTEST_REQPASS: 797 steps: - name: Activate WSL1 if: "contains(matrix.shell, 'wsl')" diff --git a/.projects/ansible-compat b/.projects/ansible-compat index 9b4314ff43..99f7703bf0 160000 --- a/.projects/ansible-compat +++ b/.projects/ansible-compat @@ -1 +1 @@ -Subproject commit 9b4314ff430d4958084ce3a7758844a47b443344 +Subproject commit 99f7703bf06999b244e93ea51e14e69ffed8ddfe diff --git a/examples/playbooks/bug-core-warning-unique-filter-fallback.yml b/examples/playbooks/bug-core-warning-unique-filter-fallback.yml new file mode 100644 index 0000000000..5639668ad3 --- /dev/null +++ b/examples/playbooks/bug-core-warning-unique-filter-fallback.yml @@ -0,0 +1,11 @@ +--- +- name: Fixture for test_bug_3216 + hosts: localhost + gather_facts: false + tasks: + - name: Set fact + ansible.builtin.set_fact: + qq: ["qq", "ww"] + - name: Print it + ansible.builtin.debug: + msg: "{{ qq | unique }}" diff --git a/src/ansiblelint/runner.py b/src/ansiblelint/runner.py index 74caa93a24..2cd3b38d52 100644 --- a/src/ansiblelint/runner.py +++ b/src/ansiblelint/runner.py @@ -10,6 +10,8 @@ from fnmatch import fnmatch from typing import TYPE_CHECKING, Any +from ansible_compat.runtime import AnsibleWarning + import ansiblelint.skip_utils import ansiblelint.utils from ansiblelint._internal.rules import LoadingFailureRule, WarningRule @@ -120,6 +122,14 @@ def run(self) -> list[MatchError]: warnings.simplefilter("always") matches = self._run() for warn in captured_warnings: + # Silence Ansible runtime warnings that are unactionable + # https://github.com/ansible/ansible-lint/issues/3216 + if warn.category is AnsibleWarning and isinstance(warn.source, dict): + msg = warn.source["msg"] + if msg.startswith( + "Falling back to Ansible unique filter as Jinja2 one failed", + ): + continue # For the moment we are ignoring deprecation warnings as Ansible # modules outside current content can generate them and user # might not be able to do anything about them. diff --git a/test/test_examples.py b/test/test_examples.py index 39c4eb7011..e8c384b42e 100644 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -86,3 +86,17 @@ def test_custom_kinds() -> None: # in our ansible-lint config, the test would not identify it as yaml file. assert "Examining examples/other/some.yaml-too of type yaml" in result.stderr assert "Examining examples/other/some.j2.yaml of type jinja2" in result.stderr + + +def test_bug_3216(capsys: pytest.CaptureFixture[str]) -> None: + """Check that we hide ansible-core originating warning about fallback on unique filter.""" + result = run_ansible_lint( + "-vv", + "--offline", + "examples/playbooks/bug-core-warning-unique-filter-fallback.yml", + ) + captured = capsys.readouterr() + assert result.returncode == 0 + warn_msg = "Falling back to Ansible unique filter" + assert warn_msg not in captured.err + assert warn_msg not in captured.out