Skip to content

Commit

Permalink
also assert that there are no warnings in callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Jan 29, 2025
1 parent cf9972a commit f9cec34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import yaml


IGNORED_WARNINGS = [
"Activation Key 'Test Activation Key Copy' already exists.",
"You have configured a plain HTTP server URL. All communication will happen unencrypted.",
]

TEST_PLAYBOOKS_PATH = py.path.local(__file__).realpath() / '..' / 'test_playbooks'


Expand Down Expand Up @@ -110,3 +115,13 @@ def get_ansible_version():
except pkg_resources.DistributionNotFound:
pass
return ansible_version


def assert_no_warnings(run):
for event in run.events:
# check for play level warnings
assert not event.get('event_data', {}).get('warning', False)

# check for task level warnings
event_warnings = [warning for warning in event.get('event_data', {}).get('res', {}).get('warnings', []) if warning not in IGNORED_WARNINGS]
assert [] == event_warnings, str(event_warnings)
3 changes: 2 additions & 1 deletion tests/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError:
from distutils.version import LooseVersion

from .conftest import run_playbook, get_ansible_version
from .conftest import run_playbook, get_ansible_version, assert_no_warnings


def run_playbook_callback(tmpdir, report_type):
Expand Down Expand Up @@ -59,6 +59,7 @@ def run_callback(tmpdir, report_type, vcrmode):
run = run_playbook_callback(tmpdir, report_type)
assert run.rc == 0
assert len(tmpdir.listdir()) > 0, "Directory with results is empty"
assert_no_warnings(run)
for real_file in tmpdir.listdir(sort=True):
contents = real_file.read()
contents = re.sub(r"\d+-\d+-\d+ \d+:\d+:\d+\+\d+:\d+", "2000-01-01 12:00:00+00:00", contents)
Expand Down
21 changes: 4 additions & 17 deletions tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
except ImportError:
from distutils.version import LooseVersion

from .conftest import TEST_PLAYBOOKS, INVENTORY_PLAYBOOKS, run_playbook, run_playbook_vcr, get_ansible_version

IGNORED_WARNINGS = [
"Activation Key 'Test Activation Key Copy' already exists.",
"You have configured a plain HTTP server URL. All communication will happen unencrypted.",
]
from .conftest import TEST_PLAYBOOKS, INVENTORY_PLAYBOOKS, run_playbook, run_playbook_vcr, get_ansible_version, assert_no_warnings

ANSIBLE_SUPPORTS_MODULE_DEFAULTS = LooseVersion(get_ansible_version()) >= LooseVersion('2.12')

Expand All @@ -35,7 +30,7 @@ def test_crud(tmpdir, module, vcrmode):
run = run_playbook_vcr(tmpdir, module, record=record)
assert run.rc == 0

_assert_no_warnings(run)
assert_no_warnings(run)


@pytest.mark.parametrize('module', TEST_PLAYBOOKS)
Expand All @@ -47,7 +42,7 @@ def test_check_mode(tmpdir, module):
run = run_playbook_vcr(tmpdir, module, check_mode=True)
assert run.rc == 0

_assert_no_warnings(run)
assert_no_warnings(run)


@pytest.mark.parametrize('module', INVENTORY_PLAYBOOKS)
Expand All @@ -59,14 +54,6 @@ def test_inventory(tmpdir, module):
run = run_playbook(module, inventory=inventory)
assert run.rc == 0

_assert_no_warnings(run)

assert_no_warnings(run)

def _assert_no_warnings(run):
for event in run.events:
# check for play level warnings
assert not event.get('event_data', {}).get('warning', False)

# check for task level warnings
event_warnings = [warning for warning in event.get('event_data', {}).get('res', {}).get('warnings', []) if warning not in IGNORED_WARNINGS]
assert [] == event_warnings, str(event_warnings)

0 comments on commit f9cec34

Please sign in to comment.