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.2.0.tar.gz (75.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-6.2.0-py3-none-any.whl (70.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-testinfra-6.2.0.tar.gz
  • Upload date:
  • Size: 75.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pytest-testinfra-6.2.0.tar.gz
Algorithm Hash digest
SHA256 fbaec729a39c90917895381bee903461be1aa8dcd2f5fff6bc5600c9fe12c795
MD5 1bca0b908f1adac60a3a3cc1dfed39be
BLAKE2b-256 5504f6fa0835c21fc613423b10efc4b314cb9d7e6089aef3dc6762ecbb0f0195

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_testinfra-6.2.0-py3-none-any.whl
  • Upload date:
  • Size: 70.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for pytest_testinfra-6.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f24f41c6453e0e70f361672cabc8358b4ade1f72a1d52870e621f12bf74015e1
MD5 50f7ee7dfeb41aa21491acb55ab52356
BLAKE2b-256 f000581198052afe6bbbcf7a68132f2a3cf75768392a1876eb82720c630b582e

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