Skip to main content

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

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@master#egg=pytest-testinfra'

Write your first tests file to test_myinfra.py:

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:

$ py.test -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 ====================

Release files for pytest-testinfra 6.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-testinfra 6.8.0
File Size Uploaded
pytest-testinfra-6.8.0.tar.gz 78.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-testinfra 6.8.0
File Interpreter ABI Platform
pytest_testinfra-6.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 151.2 kB

Release files / pytest-testinfra-6.8.0.tar.gz

Download URL pytest-testinfra-6.8.0.tar.gz
Size 78.6 kB
Tags Source
SHA-256 checksum
How to use checksums
07c8c2c472aca7d83099ebc5f850d383721cd654b66c60ffbb145e45e584ff99
BLAKE2b-256 checksum
How to use checksums
a6778bdfe16da316340782b5e21d97078c362b6b338cb1a30016b36104afd1f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / pytest_testinfra-6.8.0-py3-none-any.whl

Download URL pytest_testinfra-6.8.0-py3-none-any.whl
Size 72.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56ac1dfc61342632a1189091473e253db1a3cdcecce0d49d6a769f33cd264814
BLAKE2b-256 checksum
How to use checksums
28be6beef3bc9346504120987176b0ba0d3fc13cc972631344545f02d0ad9c23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

10.2.2

2 release files

10.2.1

2 release files

10.1.1

2 release files

10.1.0

2 release files

10.0.0

2 release files

9.0.0

2 release files

8.1.0

2 release files

8.0.0

2 release files

7.0.0

2 release files

This release

6.8.0 This release

2 release files

6.7.0

2 release files

6.6.0

2 release files

6.5.0

2 release files

6.4.0

2 release files

6.3.0

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page