Skip to content

Commit

Permalink
Add fixture to test pre-2.11 ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrews committed Nov 17, 2021
1 parent 72629e9 commit 1070c4c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,39 @@ def is_pre_ansible28():
pass


@pytest.fixture(scope='session')
def is_pre_ansible211():
"""
Check if the version of Ansible is less than 2.11.
We test with either ansible-core (>=2.11), ansible-base (==2.10), and ansible (<=2.9).
Since either might be installed, based on the test environment, test in succession
until one is found.
"""

try:
if pkg_resources.get_distribution('ansible-core').version:
return False
except pkg_resources.DistributionNotFound:
try:
if pkg_resources.get_distribution('ansible-base').version:
return True
except pkg_resources.DistributionNotFound:
return True


@pytest.fixture(scope='session')
def skipif_pre_ansible28(is_pre_ansible28):
if is_pre_ansible28:
pytest.skip("Valid only on Ansible 2.8+")


@pytest.fixture(scope='session')
def skipif_pre_ansible211(is_pre_ansible211):
if is_pre_ansible211:
pytest.skip("Valid only on Ansible 2.11+")


# TODO: determine if we want to add docker / podman
# to zuul instances in order to run these tests
def pytest_generate_tests(metafunc):
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def test_run_role(project_fixtures):
assert 'Hello World!' in stdout


def test_get_role_list(project_fixtures):
def test_get_role_list(project_fixtures, skipif_pre_ansible211):
'''
Test get_role_list() running locally, specifying a playbook directory
containing our test role.
Expand All @@ -378,7 +378,7 @@ def test_get_role_list(project_fixtures):


@pytest.mark.test_all_runtimes
def test_get_role_list_within_container(project_fixtures, runtime):
def test_get_role_list_within_container(project_fixtures, runtime, skipif_pre_ansible211):
'''
Test get_role_list() running in a container. Because the test container
has no roles/collections installed, the returned output should be empty.
Expand Down

0 comments on commit 1070c4c

Please sign in to comment.