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@main#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 ====================

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-testinfra-10.0.0.tar.gz (84.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_testinfra-10.0.0-py3-none-any.whl (76.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest-testinfra-10.0.0.tar.gz.

File metadata

  • Download URL: pytest-testinfra-10.0.0.tar.gz
  • Upload date:
  • Size: 84.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pytest-testinfra-10.0.0.tar.gz
Algorithm Hash digest
SHA256 2fb7d0185458a9ba669ff14d0ddbec8b3900c6bde3fb6fad9b097374ce4ab77d
MD5 33cba3c07ec9beef216fba7d1bdf4f53
BLAKE2b-256 5141c585cc6763a6b476b6e2f5a48442bf2e2e74edeac98e634a3521a63c3fe2

See more details on using hashes here.

File details

Details for the file pytest_testinfra-10.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_testinfra-10.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03be2824aece7a5eda8bb4f9dbed4d8c821efcfbbc13e13df17f392c229a44ed
MD5 9d696cc52cf524378830807e201b5f78
BLAKE2b-256 7a98902dd6f00d872c7e3ce98bfcfdf291e9c302d7d49ea392f4f5f747fb1ec6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page