diff --git a/tests/conftest.py b/tests/conftest.py index 8a5b95830..43ccedd0d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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' @@ -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) diff --git a/tests/test_callback.py b/tests/test_callback.py index 3a8ca5569..85fdf00f7 100644 --- a/tests/test_callback.py +++ b/tests/test_callback.py @@ -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): @@ -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) diff --git a/tests/test_crud.py b/tests/test_crud.py index 9138921b4..859931879 100644 --- a/tests/test_crud.py +++ b/tests/test_crud.py @@ -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') @@ -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) @@ -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) @@ -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)