skillfed

pytest-ansible

Plugin for pytest to simplify calling ansible modules from tests or fixtures

pytest-ansible v26.8.0 983.4K downloads/30d#4,580 on PyPI225
Permissive license MIT Active released

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-ansible

uv

uv add pytest-ansible

poetry

poetry add pytest-ansible

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTopic :: Utilities

Tags

ansible pytest plugintest ansible modules with pytestansible inventory in testspytest ansible integrationrun ansible from pytestansible collection unit testing
ansible-testingdeprecated-planned

More Utilities packages