skillfed

pytest-testinfra

Test infrastructures

pytest-testinfra v10.2.2 1.5M downloads/30d#3,779 on PyPI
Permissive license AGING released

What it is and what it does

Pytest-testinfra is a pytest plugin that brings infrastructure testing into Python. Instead of writing shell scripts or separate test frameworks to verify server configuration, you write pytest test functions that inspect the actual state of your infrastructure—checking whether files exist with the right permissions, packages are installed, services are running, users have correct groups, and so on. It acts as a Python equivalent to Serverspec, integrating directly with pytest's test runner and reporting.

You typically use it after provisioning servers with tools like Ansible, Puppet, Chef, or Salt to verify that the configuration management actually produced the desired state. The package provides a `host` fixture that abstracts away the details of connecting to and querying target machines, so your tests read like straightforward assertions rather than shell command chains.

Use it for:

  • Verify that Ansible playbooks or Puppet manifests correctly installed packages and configured services on target servers.
  • Assert file permissions, ownership, and content match infrastructure-as-code specifications after deployment.
  • Check that running services are enabled and listening on expected ports after configuration management runs.
  • Test user and group creation, membership, and home directory setup across a fleet of servers.
  • Validate system state in CI/CD pipelines after infrastructure provisioning to catch configuration drift early.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A pytest plugin that lets you write Python unit tests to verify the actual state of servers—files, packages, services, users—configured by infrastructure management tools.

Yes, if you manage infrastructure with configuration tools and want to verify actual server state in Python. The single pytest dependency keeps install friction low, and the permissive license poses no barrier. The aging maintenance status (502 days since last release) is a caution: the package is stable but may respond slowly to bugs or new requirements. Suitable for production use in established infrastructure workflows.

Install

pytest-testinfra on PyPI

pip

pip install pytest-testinfra

uv

uv add pytest-testinfra

poetry

poetry add pytest-testinfra

Installing pytest-testinfra

Before you install

Low friction: a single runtime dependency on pytest, distributed as a wheel. Maintenance status is aging—last release was 502 days ago—so expect slower response to issues, though the package is marked Production/Stable.

License in practice

Apache License 2.0 (permissive). You can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.

Quickstart

pip install pytest-testinfra

# In test_myinfra.py:
def test_passwd_file(host):
    passwd = host.file("/etc/passwd")
    assert passwd.contains("root")
    assert passwd.user == "root"

pytest -v test_myinfra.py

Requires Python 3.9 or later. Tests must run on or have network access to the target servers being inspected.

Verify before relying

  • Whether the package supports all major configuration management tools (Salt, Ansible, Puppet, Chef) equally or has gaps in any.
  • Current maintenance activity and responsiveness to bug reports, given the 502-day gap since last release.
  • Whether remote testing over SSH or other protocols is fully documented and production-ready.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance aging — 502 days since the last release
First released
Downloads 1,545,408/month — #3,779 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_testinfra-10.2.2-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: ConsoleFramework :: PytestIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsLicense :: OSI Approved :: Apache Software LicenseOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.9Topic :: Software Development :: TestingTopic :: System :: Systems Administration

Tags

infrastructure testing pythonserver state verificationpytest infrastructure testsansible puppet chef testingconfiguration management validationinfrastructure as code testingsystem state assertions
infrastructure-testingconfiguration-managementserver-validation

More Testing packages