pytest-ansible
Plugin for pytest to simplify calling ansible modules from tests or fixtures
What it is and what it does
pytest-ansible is a pytest plugin that bridges Ansible and pytest testing workflows. It was originally designed to let you call Ansible modules and iterate over inventory from inside test functions, eliminating the need for shell scripting. The plugin has been actively maintained since July 2014 and supports Python 3.10+ and ansible-core 2.14+.
However, the maintainers have announced planned end-of-life in December 2026, as the broader ecosystem—including plain pytest, ansible-test, Molecule, tox-ansible, and ansible-dev-environment—now provides better-integrated solutions for collection testing and orchestration. The plugin remains functional and installable for existing users, but the documentation includes migration patterns using parametrize and subprocess helpers to replace its fixtures. If you are starting a new project, the migration paths in the documentation are the recommended approach.
Use it for:
- Run unit tests for Ansible collection modules using pytest with only Python 3.10+ and ansible-core installed.
- Iterate over hosts and groups from an Ansible inventory within pytest parametrized tests without writing shell wrappers.
- Execute ad-hoc Ansible module calls from pytest test functions to validate module behavior in isolation.
- Integrate Ansible module testing into existing pytest CI pipelines for collections under active development.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that integrates Ansible into test functions, allowing you to call Ansible modules and iterate over inventory hosts directly from pytest tests.
Yes, if you have an existing pytest-ansible codebase or need to test Ansible modules in pytest today—the plugin is stable and actively maintained. However, no for new projects: the maintainers recommend using plain pytest with parametrize and subprocess helpers (documented in the package), or Molecule for multi-host integration. Plan for migration before December 2026 EOL.
Install
pytest-ansible on PyPI
pip
pip install pytest-ansibleuv
uv add pytest-ansiblepoetry
poetry add pytest-ansibleInstalling pytest-ansible
Before you install
Low friction install with a wheel distribution. Actively maintained as of August 2026, though the project is planned for end-of-life in December 2026; existing users should pin releases if long-term stability is required.
License in practice
MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install pytest-ansible
# In tests/conftest.py or test file:
import subprocess
def test_ping(hostname: str) -> None:
subprocess.run(
["ansible", "-i", "inventory", hostname, "-m", "ping"],
check=True,
)
Requires Python 3.10 or newer and ansible-core 2.14 or newer under active upstream support.
Verify before relying
- Whether the deprecated status and December 2026 EOL timeline affects your project's long-term maintenance plans.
- Whether existing pytest-ansible fixtures in your codebase are compatible with the recommended migration patterns (parametrize, subprocess helpers).
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — ansible-compat, ansible-core, cffi, packaging, pytest, pytest-xdist, typing-extensions |
| Maintenance | actively maintained — 2 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 983,385/month — #4,580 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_ansible-26.8.0-py3-none-any.whl
Keywords: ansible, pytest, testing
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
tox-ansibleA tox plugin that orchestrates testing of…
permissive · top 15,000 on PyPI
ansible-dev-toolsBundles and installs a curated suite of Ansible…
copyleft · top 15,000 on PyPI
molecule-vagrantMolecule Vagrant Plugin enables Vagrant-based…
permissive · top 15,000 on PyPI
moleculeMolecule is an Ansible testing framework for…
permissive · top 5,000 on PyPI
molecule-multipassIntegrates Multipass virtual machines as a…
permissive · top 15,000 on PyPI
molecule-pluginsProvides driver plugins for molecule that…
permissive · top 5,000 on PyPI
pytest-testinfraA pytest plugin that lets you write Python unit…
permissive · top 5,000 on PyPI
testinfraTestinfra lets you write Python unit tests that…
permissive · top 15,000 on PyPI
molecule-dockerMolecule Docker Plugin enables Docker…
permissive · top 15,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI