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@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.6.0.tar.gz (78.3 kB view details)

Uploaded Source

Built Distribution

pytest_testinfra-6.6.0-py3-none-any.whl (72.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-testinfra-6.6.0.tar.gz
  • Upload date:
  • Size: 78.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytest-testinfra-6.6.0.tar.gz
Algorithm Hash digest
SHA256 c2c0af72e51d84f72306045b551a91ac8a2cef2ca1fa87636ee64ceaa0f219c5
MD5 f47993370ccc0eefe70d500ddfa1c88d
BLAKE2b-256 f457551ebbc6ff33506eddf09b622c65fda006ca4cb2e82fdf772e07bf443b59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_testinfra-6.6.0-py3-none-any.whl
  • Upload date:
  • Size: 72.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytest_testinfra-6.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3aac5453a8b0e61b00539d8560442e862ce04ce1e31d08fd44500a4e43d3a989
MD5 60a8308af9e289ae0e4a7fea0197276e
BLAKE2b-256 494ce1fa1215db5471d284ee1dc6597d06c805a9ccf7f2107019943f141aea2b

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