Skip to main content

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

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.1.tar.gz (44.6 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-10.2.1-py3-none-any.whl (76.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_testinfra-10.2.1.tar.gz
  • Upload date:
  • Size: 44.6 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.1.tar.gz
Algorithm Hash digest
SHA256 c468fc58f6493f3ff17c8d3e8151d6d5ebeb5c40f23d9e4590e1fd8083881ef2
MD5 a5aab3f5b0e907291348fb8a53293a8d
BLAKE2b-256 7d8551383375c40561f47ca316c1d3f3e661e55a252618be8b9a8323246b0b1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_testinfra-10.2.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_testinfra-10.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f80507213d2b92a987c22e6ebbf9eb7c9550dd4daed9164fa29778058bd9270c
MD5 44c2deb55c2607b4a0c3dd982052bdb5
BLAKE2b-256 85b20436e2556e291620b5b3a005e0e4df5c690ff3b84418a70d6cc778a92619

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_testinfra-10.2.1-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.

Release history Release notifications | RSS feed

10.2.2

2 files

This release

10.2.1 This release

2 files

10.1.1

2 files

10.1.0

2 files

10.0.0

2 files

9.0.0

2 files

8.1.0

2 files

8.0.0

2 files

7.0.0

2 files

6.8.0

2 files

6.7.0

2 files

6.6.0

2 files

6.5.0

2 files

6.4.0

2 files

6.3.0

2 files

6.2.0

2 files

6.1.0

2 files

6.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page