pytest-ansible
pytest-ansible is a free pytest plugin for using Ansible in tests and running Ansible collection unit tests.
What pytest-ansible is
pytest-ansible is a free pytest plugin for using Ansible in tests and running Ansible collection unit tests. Its pytest-ansible-units plugin supports collection unit tests and testing individual modules in isolation. Legacy fixtures including ansible_module, ansible_adhoc, localhost, and ansible_facts let tests call modules, work with inventory, and access system facts. The project runs locally and targets Ansible collection authors and developers writing pytest tests that use Ansible. Installation is shown with pip install pytest-ansible. Supported versions listed by the project are Python 3.10 or newer and ansible-core 2.14 or newer. The documented ecosystem includes pytest, Ansible, Ansible collections, and a deprecated Molecule integration. That integration does not support Molecule shared_state or --workers. Migration guidance recommends ADE with plain pytest for collection unit tests, tox-ansible for collection CI, and the Molecule CLI for scenarios. The repository identifies an MIT license.
Good
- Free MIT-licensed project
- Runs Ansible collection unit tests
- Tests individual modules
- Provides Ansible pytest fixtures
- Local execution model
Watch out
- Deprecated project
- Planned end of life in December 2026
- Molecule integration is deprecated
- No shared_state or --workers support
Who it suits
It suits Ansible collection authors and developers writing pytest tests for modules, inventory, and system facts. It is intended for local testing workflows.
Verdict
pytest-ansible connects pytest with Ansible collection and module testing through plugins and fixtures. Its deprecation and planned 2026 end of life make the documented migration paths important for ongoing projects.
The facts
Each one read from pytest-ansible's own pages, with the date it was checked.
What it does
- Ansible fixtures
- Legacy fixtures include `ansible_module`, `ansible_adhoc`, `localhost`, and `ansible_facts` for calling modules, working with inventory, and accessing system facts from pytest tests.checked 7 Oct 2026
- Audience
- The documentation describes the plugin for Ansible collection authors and developers who want to use Ansible from pytest tests.checked 7 Oct 2026
- Collection testing
- Its `pytest-ansible-units` plugin lets users run Ansible collection unit tests with pytest and test individual modules.checked 7 Oct 2026
- Deprecation
- The project is deprecated and has a planned end of life in December 2026.checked 8 Oct 2026
- Installation
- The README instructs users to install the plugin with pip install pytest-ansible.checked 8 Oct 2026
- Integrations
- The documented ecosystem includes pytest, Ansible and Ansible collections, and legacy integration with Molecule.checked 7 Oct 2026
- Intended users
- The documented use cases focus on Ansible collection authors and people writing pytest tests that call Ansible modules or use Ansible inventory.checked 8 Oct 2026
- Legacy fixtures
- Legacy fixtures include ansible_adhoc, ansible_module, localhost, and ansible_facts for interacting with Ansible from pytest tests.checked 8 Oct 2026
- License
- The project says it is free and open source under the MIT license.checked 8 Oct 2026
- Migration guidance
- The project recommends ADE with plain pytest for collection unit tests, tox-ansible for collection CI, and the Molecule CLI for scenarios.checked 8 Oct 2026
- Molecule limitation
- The pytest integration for Molecule does not support Molecule shared_state or --workers and is deprecated.checked 8 Oct 2026
- Molecule support
- Molecule scenario integration through pytest is deprecated; the README recommends using the Molecule CLI or tox-ansible instead.checked 7 Oct 2026
- Purpose
- pytest-ansible is a pytest plugin for using Ansible in tests, running Ansible collection unit tests with pytest, and exposing Molecule scenarios through a pytest fixture.checked 8 Oct 2026
- Requirements
- The project says it supports Python 3.10 or newer and ansible-core 2.14 or newer.checked 7 Oct 2026
- Runtime requirements
- The project lists Python 3.10 or newer and ansible-core 2.14 or newer as supported versions.checked 8 Oct 2026
- Security
- The repository links to a security policy, but the opened project pages do not state security certifications or compliance claims.checked 7 Oct 2026
- Security policy
- The repository links a security policy, but the opened page did not expose policy details.checked 8 Oct 2026
- Support
- The README directs users with problems to file a GitHub issue with a detailed description.checked 8 Oct 2026
- Unit testing
- Its pytest-ansible-units plugin supports running Ansible collection unit tests with pytest and testing individual Ansible modules in isolation.checked 8 Oct 2026
Alternatives to pytest-ansible
- 1
Chef InSpec
Free planOpen sourceAPILinuxmacOSSelf-hosted8.0From $59 a year - 2

AWS CloudFormation
Free planiOSWebAPILinux7.7Free plan - 3

CIS-CAT Pro Assessor
Free planAPILinuxmacOSSelf-hosted7.7From $2,400 a year - 4
Test Kitchen
Free planOpen sourceAPILinuxmacOSSelf-hosted7.2Free plan - 5
kube-score
Free planWebLinuxmacOSSelf-hosted7.0Free plan - 6
Conftest
Free planLinuxmacOSWindows6.8Free plan
