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

Release files for pytest-testinfra 10.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-testinfra 10.2.2
File Size Uploaded
pytest_testinfra-10.2.2.tar.gz 76.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-testinfra 10.2.2
File Interpreter ABI Platform
pytest_testinfra-10.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 153.1 kB

Release files / pytest_testinfra-10.2.2.tar.gz

Download URL pytest_testinfra-10.2.2.tar.gz
Size 76.2 kB
Tags Source
SHA-256 checksum
How to use checksums
537fd5eb88da618c1f461248aa20594cf8d44512e8519b239837e83875e1e9cd
BLAKE2b-256 checksum
How to use checksums
3315b650133bb3eb3509704c7605348bec4205b6a399f7a79874ced6c30a3e15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.

Transparency log

Release files / pytest_testinfra-10.2.2-py3-none-any.whl

Download URL pytest_testinfra-10.2.2-py3-none-any.whl
Size 76.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b785602b0aa868c858e4ef121a8cc0d13a81c04b74ec0364d70969540f8e7c31
BLAKE2b-256 checksum
How to use checksums
1c758b002ad110ae4a71bce9bb47020ee77176e27defe99ce6d7b62e52debeb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

10.2.2 This release

2 release files

10.2.1

2 release files

10.1.1

2 release files

10.1.0

2 release files

10.0.0

2 release files

9.0.0

2 release files

8.1.0

2 release files

8.0.0

2 release files

7.0.0

2 release files

6.8.0

2 release files

6.7.0

2 release files

6.6.0

2 release files

6.5.0

2 release files

6.4.0

2 release files

6.3.0

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.0

2 release 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