skip to navigation
skip to content

testinfra 1.8.0

Test infrastructures

Latest documentation:


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

Quick start

Install testinfra using pip:

$ pip install testinfra

# or install the devel version
$ pip install 'git+'

Write your first tests file to

def test_passwd_file(host):
    passwd = host.file("/etc/passwd")
    assert passwd.contains("root")
    assert passwd.user == "root"
    assert == "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:

$ py.test -v

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

=================== 3 passed in 0.66 seconds ====================
File Type Py Version Uploaded on Size
testinfra-1.8.0-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2017-09-29 52KB
testinfra-1.8.0.tar.gz (md5) Source 2017-09-29 57KB