pytest-testinfra is a free, open source cloud infrastructure management project written in Python and released under Apache-2.0. It has 2,476 GitHub stars, 358 forks and 147 open issues, and was last pushed 2 months ago. On this registry it ranks #33 of 43 tracked projects in Cloud Infrastructure Management, with 5 head-to-head comparisons available.

What is pytest-testinfra?

What it is

Testinfra is Python tool. It is pytest plugin. It tests actual state of servers. Servers configured by management tools like Salt, Ansible, Puppet, Chef. It lives in Python and pytest ecosystem for infrastructure testing, DevOps, and infrastructure-as-code work.

Problem it solves: configuration management tools change servers, but teams need check result. Testinfra lets users write Python unit tests for files, packages, services. This gives direct verification after management run. It aims to be Serverspec equivalent in Python. Registry facts list Python language, Apache License 2.0, 2477 stars, 359 forks, 147 open issues, 12 years age, and last push 2026-07-20T20:32:30Z.

Key capabilities

  • Users write Python test files, such as test_myinfra.py, and run them with pytest -v.
  • Tests can inspect files, including path, content, user, group, and mode, as shown with /etc/passwd.
  • Tests can check packages, including installed state and version prefix, as shown with nginx and 1.2.
  • Tests can check services, including running and enabled state, as shown with nginx.
  • README names Salt, Ansible, Puppet, and Chef as management tools for configured servers.
  • Topic list connects it to Docker, Kubernetes, Nagios, devops, devops-tools, infrastructure-as-code, infrastructure-testing, pytest-plugin, and python.
  • It installs as pytest-testinfra, and development version can install from git main branch.

Who uses it and how

  • Infrastructure teams test server state after configuration by Ansible, Chef, Puppet, or Salt.
  • Python and pytest users add infrastructure checks as normal pytest tests.
  • DevOps and infrastructure-as-code users use it for testing actual state, not only configuration code.
  • Docker and Kubernetes topics connect it to those platforms, but README does not detail specific commands for them.
  • Nagios topic connects it to that platform, but README does not describe integration with Nagios.

Getting started

Install with pip install pytest-testinfra, or install development version with pip install 'git+https://github.com/pytest-dev/pytest-testinfra@main#egg=pytest-testinfra'. Write test_myinfra.py and run pytest -v test_myinfra.py.

When to use it — and when not to

Use it when Python, pytest, and direct checks of files, packages, and services fit infrastructure verification. Do not use it if active maintenance matters, because README says project is not actively maintained and issue or pull request responses may be delayed for several months. Provided facts do not list paid products it replaces, and they do not mention database, storage, SMTP, or other self-hosting operations.

project readme (upstream, from github) — read inline

################################## Testinfra test your infrastructure ##################################

Latest documentation: https://testinfra.readthedocs.io/en/latest

.. important::

Maintenance Notice

This project is currently not actively maintained, and responses to issues or pull requests may be delayed for several months. Please consider this when using the project and feel free to contribute via pull requests, which will be reviewed as time permits. Thank you for your understanding!

About

With Testinfra you can write unit tests in Python to test actual state of your servers configured by management tools like Salt_, Ansible_, Puppet_, Chef_ and so on.

Testinfra aims to be a Serverspec_ equivalent in python and is written as a plugin to the powerful Pytest_ test engine

License

Apache License 2.0 _

The logo is licensed under the Creative Commons NoDerivatives 4.0 License _ If you have some other use in mind, contact us.

Quick start

Install testinfra using pip::

$ pip install pytest-testinfra

# or install the devel version
$ pip install 'git+https://github.com/pytest-dev/pytest-testinfra@main#egg=pytest-testinfra'

Write your first tests file to test_myinfra.py:

.. code-block:: python

def test_passwd_file(host):
    passwd = host.file("/etc/passwd")
    assert passwd.contains("root")
    assert passwd.user == "root"
    assert passwd.group == "root"
    assert passwd.mode == 0o644


def test_nginx_is_installed(host):
    nginx = host.package("nginx")
    assert nginx.is_installed
    assert nginx.version.startswith("1.2")


def test_nginx_running_and_enabled(host):
    nginx = host.service("nginx")
    assert nginx.is_running
    assert nginx.is_enabled

And run it::

$ pytest -v test_myinfra.py


====================== test session starts ======================
platform linux -- Python 2.7.3 -- py-1.4.26 -- pytest-2.6.4
plugins: testinfra
collected 3 items

test_myinfra.py::test_passwd_file[local] PASSED
test_myinfra.py::test_nginx_is_installed[local] PASSED
test_myinfra.py::test_nginx_running_and_enabled[local] PASSED

=================== 3 passed in 0.66 seconds ====================

.. _Salt: https://saltstack.com/ .. _Ansible: https://www.ansible.com/ .. _Puppet: https://puppetlabs.com/ .. _Chef: https://www.chef.io/ .. _Serverspec: https://serverspec.org/ .. _Pytest: https://pytest.org/

Frequently asked questions

Is pytest-testinfra free to use?

pytest-testinfra is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does pytest-testinfra do?

Testinfra test your infrastructures

What is pytest-testinfra written in?

pytest-testinfra is primarily written in Python. Its source is publicly available at https://github.com/pytest-dev/pytest-testinfra, and it has 2,476 GitHub stars.