Package: tox-ansible
tox-ansibleIntroductiontox-ansibleis a utility designed to simplify the testing of Ansible content collections.Implemented as atoxplugin,tox-ansibleprovides a simple way to test Ansible content collections across multiple Python interpreters and Ansible versions.tox-ansibleuses familiar python testing tools to perform the actual testing. It usestoxto create and manage the testing environments,ansible-test sanityto run the sanity tests, andpytestto run the unit and integration tests. This eliminated the black box nature of other approaches and allowed for more control over the testing process.When used on a local development system, each of the environments are left intact after a test run. This allows for easy debugging of failed tests for a given test type, python interpreter and Ansible version.By usingtoxto create and manage the testing environments, Test outcomes should always be the same on a local development system as they are in a CI/CD pipeline.toxvirtual environments are created in the.toxdirectory. These are easily deleted and recreated if needed.InstallationInstall from pypi:pipinstalltox-ansibleUsageFrom the root of your collection, create an emptytox-ansible.inifile and list the available environments:touchtox-ansible.ini
toxlist--ansible--conftox-ansible.iniA list of dynamically generated Ansible environments will be displayed:default environments:
...
integration-py3.11-2.14      -> Integration tests for ansible.scm using ansible-core 2.14 and python 3.11
integration-py3.11-devel     -> Integration tests for ansible.scm using ansible-core devel and python 3.11
integration-py3.11-milestone -> Integration tests for ansible.scm using ansible-core milestone and python 3.11
...
sanity-py3.11-2.14           -> Sanity tests for ansible.scm using ansible-core 2.14 and python 3.11
sanity-py3.11-devel          -> Sanity tests for ansible.scm using ansible-core devel and python 3.11
sanity-py3.11-milestone      -> Sanity tests for ansible.scm using ansible-core milestone and python 3.11
...
unit-py3.11-2.14             -> Unit tests for ansible.scm using ansible-core 2.14 and python 3.11
unit-py3.11-devel            -> Unit tests for ansible.scm using ansible-core devel and python 3.11
unit-py3.11-milestone        -> Unit tests for ansible.scm using ansible-core milestone and python 3.11These represent the available testing environments. Each denotes the type of tests that will be run, the Python interpreter used to run the tests, and the Ansible version used to run the tests.To run tests with a single environment, simply run the following command:tox-esanity-py3.11-2.14--ansible--conftox-ansible.iniTo run tests with multiple environments, simply add the environment names to the command:tox-esanity-py3.11-2.14,unit-py3.11-2.14--ansible--conftox-ansible.iniTo run all tests of a specific type in all available environments, use the factor-fflag:tox-funit--ansible-pauto--conftox-ansible.iniTo run all tests across all available environments:tox--ansible-pauto--conftox-ansible.iniNote: The-p autoflag will run multiple tests in parallel.
Note: The specific Python interpreter will need to be pre-installed on your system, e.g.:sudodnfinstallpython3.9To review the specific commands and configuration for each of the integration, sanity, and unit factors:toxconfig--ansible--conftox-ansible.iniGenerate specific GitHub action matrix as per scope mentioned with--matrix-scope:tox--ansible--gh-matrix--matrix-scopeunit--conftox-ansible.iniA list of dynamically generated Ansible environments will be displayed specifically for unit tests:[
  {
    "description": "Unit tests using ansible 2.9 and python 3.8",
    "factors": [
      "unit",
      "py3.8",
      "2.9"
    ],
    "name": "unit-py3.8-2.9",
    "python": "3.8"
  },
  ...
  {
    "description": "Unit tests using ansible-core milestone and python 3.12",
    "factors": [
      "unit",
      "py3.12",
      "milestone"
    ],
    "name": "unit-py3.12-milestone",
    "python": "3.12"
  }
]Configurationtox-ansibleshould be configured using atox-ansible.inifile. Using atox-ansible.inifile allows for the introduction of thetox-ansibleplugin to a repository that may already have an existingtoxconfiguration without conflicts. If no configuration overrides are needed, thetox-ansible.inifile may be empty but should be present. In addition to alltoxsupported keywords theansiblesection andskipkeyword are available:# tox-ansible.ini[ansible]skip=2.9develThis will skip tests in any environment that uses Ansible 2.9 or the devel branch. The list of strings is used for a simple string in string comparison of environment names. Here is theguideto overridetox-ansibleenvironment configuration.Release processtox-ansibleis released withCalVerscheme version numbers. The particular scheme we are using isYY.MM.MICRO, meaning that a release in March 2025 will be named25.3.0, and if a patch (ie, non-feature) release is required for that release, it will be named 25.3.1, even if it is released in April. The month will not increment until a new version with features or other significant changes is released. More details about calver release process can be seenhere.Note to version 1.x usersUsers of tox-ansible v1 should use the stable/1.x branch because the default branch is a rewrite of the plugin for tox 4.0+ which is not backward compatible with the old plugin.Version 1 of the plugin had native support for molecule. Please see the "Running molecule scenarios" above for an alternative approach.LicenseMIT