Skip to main content

Test infrastructures

Project description

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/philpep/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 ====================

Project details


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-6.0.0.tar.gz (73.6 kB view details)

Uploaded Source

Built Distribution

pytest_testinfra-6.0.0-py3-none-any.whl (69.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-testinfra-6.0.0.tar.gz
  • Upload date:
  • Size: 73.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.1

File hashes

Hashes for pytest-testinfra-6.0.0.tar.gz
Algorithm Hash digest
SHA256 1731dc5bb2802ef0efb923589870b23936c6226152d4b092ca6e30cc5eb77cab
MD5 34d3d243ccaef1de0e09437e90251cd4
BLAKE2b-256 de4758d60003560bafa94e191c139311e7503011306ceb6d90feaa9c330540e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_testinfra-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 69.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.1

File hashes

Hashes for pytest_testinfra-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f582e995db337b3a400aa534029e302373cf1c9c2d35980c2a3361b91eafef4f
MD5 644a6ba5258802c40551bceda07e47ef
BLAKE2b-256 62c08c0d007aef0121a31c78bd5363c0c4ea15b17845c782ce0fcd70f97926a6

See more details on using hashes here.

Supported by

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