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

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

Uploaded Source

Built Distribution

pytest_testinfra-10.1.1-py3-none-any.whl (76.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-testinfra-10.1.1.tar.gz
  • Upload date:
  • Size: 86.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.2

File hashes

Hashes for pytest-testinfra-10.1.1.tar.gz
Algorithm Hash digest
SHA256 a876f1453a01b58d94d9d936dd50344c2c01ac7880a2b41d15bdf233aed9cf1f
MD5 72454646846a0f9a798ffb8440bc9953
BLAKE2b-256 5315354adf3dd9635b554b27eb0167216e02bebed1796035991999c32b5081af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_testinfra-10.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b990dc7d77b49a1bba24818fbff49b6171d8c46d606fb5ca86b937de690d7062
MD5 90207bb8ea36fa787b7622da1ebb1647
BLAKE2b-256 6ba8e66b4ef547c8ff86b9c3a4744c296b879a2c6e98f4796f4bee66b911762b

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