tox-ansible


Nametox-ansible JSON
Version 24.2.0 PyPI version JSON
download
home_page
SummaryA radical approach to testing ansible content
upload_time2024-02-09 09:19:27
maintainer
docs_urlNone
author
requires_python>=3.9
licenseMIT
keywords ansible collections tox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tox-ansible

## Introduction

`tox-ansible` is a utility designed to simplify the testing of Ansible content collections.

Implemented as a `tox` plugin, `tox-ansible` provides a simple way to test Ansible content collections across multiple Python interpreters and Ansible versions.

`tox-ansible` uses familiar python testing tools to perform the actual testing. It uses `tox` to create and manage the testing environments, `ansible-test sanity` to run the sanity tests, and `pytest` to 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 using `tox` to 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.

`tox` virtual environments are created in the `.tox` directory. These are easily deleted and recreated if needed.

## Installation

Install from pypi:

```bash
pip install tox-ansible
```

## Usage

From the root of your collection, create an empty `tox-ansible.ini` file and list the available environments:

```bash
touch tox-ansible.ini
tox list --ansible --conf tox-ansible.ini
```

A 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.11
```

These 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:

```bash
tox -e sanity-py3.11-2.14 --ansible --conf tox-ansible.ini
```

To run tests with multiple environments, simply add the environment names to the command:

```bash
tox -e sanity-py3.11-2.14,unit-py3.11-2.14 --ansible --conf tox-ansible.ini
```

To run all tests of a specific type in all available environments, use the factor `-f` flag:

```bash
tox -f unit --ansible -p auto --conf tox-ansible.ini
```

To run all tests across all available environments:

```bash
tox --ansible -p auto --conf tox-ansible.ini
```

Note: The `-p auto` flag will run multiple tests in parallel.
Note: The specific Python interpreter will need to be pre-installed on your system, e.g.:

```bash
sudo dnf install python3.9
```

To review the specific commands and configuration for each of the integration, sanity, and unit factors:

```bash
tox config --ansible --conf tox-ansible.ini
```

Generate specific GitHub action matrix as per scope mentioned with `--matrix-scope`:

```bash
tox --ansible --gh-matrix --matrix-scope unit --conf tox-ansible.ini
```

A 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"
  }
]
```

## Configuration

`tox-ansible` should be configured using a `tox-ansible.ini` file. Using a `tox-ansible.ini` file allows for the introduction of the `tox-ansible` plugin to a repository that may already have an existing `tox` configuration without conflicts. If no configuration overrides are needed, the `tox-ansible.ini` file may be empty but should be present. In addition to all `tox` supported keywords the `ansible` section and `skip` keyword are available:

```ini
# tox-ansible.ini
[ansible]
skip =
    2.9
    devel
```

This 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 the [guide] to override `tox-ansible` environment configuration.

[guide]: https://ansible.readthedocs.io/projects/tox-ansible/configuration/#overriding-the-configuration

## Release process

`tox-ansible` is released with [CalVer] scheme version numbers. The particular scheme we are using is `YY.MM.MICRO`, meaning that a release in March 2025 will be named `25.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 seen [here].

[here]: https://ansible.readthedocs.io/projects/team-devtools/guides/calver/
[CalVer]: https://calver.org/

## Note to version 1.x users

Users 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.

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "tox-ansible",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Ansible by Red Hat <info@ansible.com>",
    "keywords": "ansible,collections,tox",
    "author": "",
    "author_email": "\"Bradley A. Thornton\" <bthornto@redhat.com>",
    "download_url": "https://files.pythonhosted.org/packages/c3/08/e6da6bb167f544fd60fa184d1bf121cd4bbe59363680c954b3267ed56036/tox-ansible-24.2.0.tar.gz",
    "platform": null,
    "description": "# tox-ansible\n\n## Introduction\n\n`tox-ansible` is a utility designed to simplify the testing of Ansible content collections.\n\nImplemented as a `tox` plugin, `tox-ansible` provides a simple way to test Ansible content collections across multiple Python interpreters and Ansible versions.\n\n`tox-ansible` uses familiar python testing tools to perform the actual testing. It uses `tox` to create and manage the testing environments, `ansible-test sanity` to run the sanity tests, and `pytest` to run the unit and integration tests. This eliminated the black box nature of other approaches and allowed for more control over the testing process.\n\nWhen 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.\n\nBy using `tox` to 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.\n\n`tox` virtual environments are created in the `.tox` directory. These are easily deleted and recreated if needed.\n\n## Installation\n\nInstall from pypi:\n\n```bash\npip install tox-ansible\n```\n\n## Usage\n\nFrom the root of your collection, create an empty `tox-ansible.ini` file and list the available environments:\n\n```bash\ntouch tox-ansible.ini\ntox list --ansible --conf tox-ansible.ini\n```\n\nA list of dynamically generated Ansible environments will be displayed:\n\n```\n\ndefault environments:\n...\nintegration-py3.11-2.14      -> Integration tests for ansible.scm using ansible-core 2.14 and python 3.11\nintegration-py3.11-devel     -> Integration tests for ansible.scm using ansible-core devel and python 3.11\nintegration-py3.11-milestone -> Integration tests for ansible.scm using ansible-core milestone and python 3.11\n...\nsanity-py3.11-2.14           -> Sanity tests for ansible.scm using ansible-core 2.14 and python 3.11\nsanity-py3.11-devel          -> Sanity tests for ansible.scm using ansible-core devel and python 3.11\nsanity-py3.11-milestone      -> Sanity tests for ansible.scm using ansible-core milestone and python 3.11\n...\nunit-py3.11-2.14             -> Unit tests for ansible.scm using ansible-core 2.14 and python 3.11\nunit-py3.11-devel            -> Unit tests for ansible.scm using ansible-core devel and python 3.11\nunit-py3.11-milestone        -> Unit tests for ansible.scm using ansible-core milestone and python 3.11\n```\n\nThese 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.\n\nTo run tests with a single environment, simply run the following command:\n\n```bash\ntox -e sanity-py3.11-2.14 --ansible --conf tox-ansible.ini\n```\n\nTo run tests with multiple environments, simply add the environment names to the command:\n\n```bash\ntox -e sanity-py3.11-2.14,unit-py3.11-2.14 --ansible --conf tox-ansible.ini\n```\n\nTo run all tests of a specific type in all available environments, use the factor `-f` flag:\n\n```bash\ntox -f unit --ansible -p auto --conf tox-ansible.ini\n```\n\nTo run all tests across all available environments:\n\n```bash\ntox --ansible -p auto --conf tox-ansible.ini\n```\n\nNote: The `-p auto` flag will run multiple tests in parallel.\nNote: The specific Python interpreter will need to be pre-installed on your system, e.g.:\n\n```bash\nsudo dnf install python3.9\n```\n\nTo review the specific commands and configuration for each of the integration, sanity, and unit factors:\n\n```bash\ntox config --ansible --conf tox-ansible.ini\n```\n\nGenerate specific GitHub action matrix as per scope mentioned with `--matrix-scope`:\n\n```bash\ntox --ansible --gh-matrix --matrix-scope unit --conf tox-ansible.ini\n```\n\nA list of dynamically generated Ansible environments will be displayed specifically for unit tests:\n\n```\n[\n  {\n    \"description\": \"Unit tests using ansible 2.9 and python 3.8\",\n    \"factors\": [\n      \"unit\",\n      \"py3.8\",\n      \"2.9\"\n    ],\n    \"name\": \"unit-py3.8-2.9\",\n    \"python\": \"3.8\"\n  },\n  ...\n  {\n    \"description\": \"Unit tests using ansible-core milestone and python 3.12\",\n    \"factors\": [\n      \"unit\",\n      \"py3.12\",\n      \"milestone\"\n    ],\n    \"name\": \"unit-py3.12-milestone\",\n    \"python\": \"3.12\"\n  }\n]\n```\n\n## Configuration\n\n`tox-ansible` should be configured using a `tox-ansible.ini` file. Using a `tox-ansible.ini` file allows for the introduction of the `tox-ansible` plugin to a repository that may already have an existing `tox` configuration without conflicts. If no configuration overrides are needed, the `tox-ansible.ini` file may be empty but should be present. In addition to all `tox` supported keywords the `ansible` section and `skip` keyword are available:\n\n```ini\n# tox-ansible.ini\n[ansible]\nskip =\n    2.9\n    devel\n```\n\nThis 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 the [guide] to override `tox-ansible` environment configuration.\n\n[guide]: https://ansible.readthedocs.io/projects/tox-ansible/configuration/#overriding-the-configuration\n\n## Release process\n\n`tox-ansible` is released with [CalVer] scheme version numbers. The particular scheme we are using is `YY.MM.MICRO`, meaning that a release in March 2025 will be named `25.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 seen [here].\n\n[here]: https://ansible.readthedocs.io/projects/team-devtools/guides/calver/\n[CalVer]: https://calver.org/\n\n## Note to version 1.x users\n\nUsers 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.\n\nVersion 1 of the plugin had native support for molecule. Please see the \"Running molecule scenarios\" above for an alternative approach.\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A radical approach to testing ansible content",
    "version": "24.2.0",
    "project_urls": null,
    "split_keywords": [
        "ansible",
        "collections",
        "tox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95cc83ecfeea83b0c7f82f8b4823e91fae6c84410b15515742102b053d19f26b",
                "md5": "1ad1ffa685b31ae3ba2d2fd5140917e1",
                "sha256": "e446f8e81ec2cb4241330839a7b7c55f28e466ed74e89055e2c7dacad2784537"
            },
            "downloads": -1,
            "filename": "tox_ansible-24.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1ad1ffa685b31ae3ba2d2fd5140917e1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10122,
            "upload_time": "2024-02-09T09:19:25",
            "upload_time_iso_8601": "2024-02-09T09:19:25.781902Z",
            "url": "https://files.pythonhosted.org/packages/95/cc/83ecfeea83b0c7f82f8b4823e91fae6c84410b15515742102b053d19f26b/tox_ansible-24.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c308e6da6bb167f544fd60fa184d1bf121cd4bbe59363680c954b3267ed56036",
                "md5": "49ab8f2674566af9a013b1acd07cc0d2",
                "sha256": "b09c5b7246db9057d1e4b62a7b4ad9dd33012426b18aff74047a28fc24f190ac"
            },
            "downloads": -1,
            "filename": "tox-ansible-24.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "49ab8f2674566af9a013b1acd07cc0d2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 31618,
            "upload_time": "2024-02-09T09:19:27",
            "upload_time_iso_8601": "2024-02-09T09:19:27.729133Z",
            "url": "https://files.pythonhosted.org/packages/c3/08/e6da6bb167f544fd60fa184d1bf121cd4bbe59363680c954b3267ed56036/tox-ansible-24.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-09 09:19:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tox-ansible"
}
        
Elapsed time: 0.17936s