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:

$ pytest -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.2.2.tar.gz (76.2 kB view details)

Uploaded Source

Built Distribution

pytest_testinfra-10.2.2-py3-none-any.whl (76.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_testinfra-10.2.2.tar.gz.

File metadata

  • Download URL: pytest_testinfra-10.2.2.tar.gz
  • Upload date:
  • Size: 76.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_testinfra-10.2.2.tar.gz
Algorithm Hash digest
SHA256 537fd5eb88da618c1f461248aa20594cf8d44512e8519b239837e83875e1e9cd
MD5 decad31f3be7bb98d101063d29e51d29
BLAKE2b-256 3315b650133bb3eb3509704c7605348bec4205b6a399f7a79874ced6c30a3e15

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_testinfra-10.2.2.tar.gz:

Publisher: release.yml on pytest-dev/pytest-testinfra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pytest_testinfra-10.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b785602b0aa868c858e4ef121a8cc0d13a81c04b74ec0364d70969540f8e7c31
MD5 aee45f4eef643772087ea1d0e79b8a72
BLAKE2b-256 1c758b002ad110ae4a71bce9bb47020ee77176e27defe99ce6d7b62e52debeb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_testinfra-10.2.2-py3-none-any.whl:

Publisher: release.yml on pytest-dev/pytest-testinfra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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