Skip to content

Commit

Permalink
Hide warning about unique filter originating from core
Browse files Browse the repository at this point in the history
Fixes: #3216
  • Loading branch information
ErwinJanssen authored and ssbarnea committed May 12, 2023
1 parent b97bf14 commit d0ee9c2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down
2 changes: 1 addition & 1 deletion .projects/ansible-compat
11 changes: 11 additions & 0 deletions examples/playbooks/bug-core-warning-unique-filter-fallback.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
10 changes: 10 additions & 0 deletions src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions test/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d0ee9c2

Please sign in to comment.