skillfed

testinfra

Test infrastructures

testinfra v6.0.0 141.2K downloads/30d#11,245 on PyPI2,478
Permissive license Active released

What it is and what it does

Testinfra is a pytest plugin that lets you write Python unit tests to verify the actual state of servers and infrastructure. Instead of testing code in isolation, you write assertions about real system state—whether files exist with the right permissions, packages are installed, services are running, and configuration is correct. It's designed as a Python equivalent to Serverspec and works with infrastructure-as-code tools like Ansible, Puppet, Chef, and Salt.

You write tests using a `host` fixture that provides methods to inspect files, packages, services, users, and other system resources. Tests run through pytest, so you get all the standard pytest features and reporting. The project is currently not actively maintained, with the latest release over 5 years old and a maintenance notice warning that responses to issues may be delayed for several months.

Use it for:

  • Verify that Ansible or Puppet playbooks correctly configured servers after deployment.
  • Test that required packages are installed and services are running on production systems.
  • Check file permissions, ownership, and content match infrastructure requirements.
  • Validate system configuration (users, groups, network settings) in automated pipelines.
  • Ensure compliance with security baselines by asserting expected system state.

Worth the install?

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

Testinfra lets you write Python unit tests that verify the actual state of servers—checking files, packages, services, and system configuration—as a pytest plugin.

Yes, if you need to test infrastructure state and can accept the maintenance risk. The package is stable and has no known vulnerabilities, but the lack of active maintenance means you may need to fork or patch it yourself if issues arise. It's well-suited for teams already using pytest and infrastructure-as-code tools, but consider whether a maintained alternative better fits your long-term needs.

Install

testinfra on PyPI

pip

pip install testinfra

uv

uv add testinfra

poetry

poetry add testinfra

Installing testinfra

Before you install

Low friction install with a single runtime dependency (pytest). However, the project is not actively maintained; the latest release was over 5 years ago, and the description explicitly warns that issue and pull request responses may be delayed for several months.

License in practice

Licensed under Apache License 2.0 (permissive), so you can use it freely in commercial and open-source projects without restrictive obligations.

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.5 or later; tests run against actual servers or local system, so the target infrastructure must be accessible.

Verify before relying

  • Whether the project accepts and merges community pull requests despite the maintenance notice.
  • Current compatibility with modern versions of pytest and Python 3.9+.
  • Whether there are maintained forks or alternative projects that provide similar functionality.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.5)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest-testinfra
Maintenance actively maintained — 2,101 days since the last release
Last repo commit
First released
Downloads 141,218/month — #11,245 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: testinfra-6.0.0-py3-none-any.whl

Development Status :: 7 - InactiveEnvironment :: 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.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: Software Development :: TestingTopic :: System :: Systems Administration

Tags

infrastructure testing pythonserver state verificationpytest infrastructure testsconfiguration compliance testingansible puppet chef testingsystem state assertionsinfrastructure as code testing
infrastructure-testingpytest-pluginserver-validation

More Testing packages