Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

also assert that there are no warnings in callback tests #1822

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 not 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 @@ -61,6 +61,7 @@ def run_callback(tmpdir, report_type, vcrmode):
assert len(tmpdir.listdir()) > 0, "Directory with results is empty"
fixture_directory = os.path.join(os.getcwd(), 'tests', 'fixtures', 'callback', 'dir_store', report_type)
assert len(tmpdir.listdir()) == len(os.listdir(fixture_directory)), "Fixture directory and output directory have a different number of files"
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
23 changes: 4 additions & 19 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,4 @@ def test_inventory(tmpdir, module):
run = run_playbook(module, inventory=inventory)
assert run.rc == 0

_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)
assert_no_warnings(run)
Loading