pytest-testinfra
Test infrastructures
What it is and what it does
Pytest-testinfra is a pytest plugin that brings infrastructure testing into Python. Instead of writing shell scripts or separate test frameworks to verify server configuration, you write pytest test functions that inspect the actual state of your infrastructure—checking whether files exist with the right permissions, packages are installed, services are running, users have correct groups, and so on. It acts as a Python equivalent to Serverspec, integrating directly with pytest's test runner and reporting.
You typically use it after provisioning servers with tools like Ansible, Puppet, Chef, or Salt to verify that the configuration management actually produced the desired state. The package provides a `host` fixture that abstracts away the details of connecting to and querying target machines, so your tests read like straightforward assertions rather than shell command chains.
Use it for:
- Verify that Ansible playbooks or Puppet manifests correctly installed packages and configured services on target servers.
- Assert file permissions, ownership, and content match infrastructure-as-code specifications after deployment.
- Check that running services are enabled and listening on expected ports after configuration management runs.
- Test user and group creation, membership, and home directory setup across a fleet of servers.
- Validate system state in CI/CD pipelines after infrastructure provisioning to catch configuration drift early.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that lets you write Python unit tests to verify the actual state of servers—files, packages, services, users—configured by infrastructure management tools.
Yes, if you manage infrastructure with configuration tools and want to verify actual server state in Python. The single pytest dependency keeps install friction low, and the permissive license poses no barrier. The aging maintenance status (502 days since last release) is a caution: the package is stable but may respond slowly to bugs or new requirements. Suitable for production use in established infrastructure workflows.
Install
pytest-testinfra on PyPI
pip
pip install pytest-testinfrauv
uv add pytest-testinfrapoetry
poetry add pytest-testinfraInstalling pytest-testinfra
Before you install
Low friction: a single runtime dependency on pytest, distributed as a wheel. Maintenance status is aging—last release was 502 days ago—so expect slower response to issues, though the package is marked Production/Stable.
License in practice
Apache License 2.0 (permissive). You can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install pytest-testinfra
# In test_myinfra.py:
def test_passwd_file(host):
passwd = host.file("/etc/passwd")
assert passwd.contains("root")
assert passwd.user == "root"
pytest -v test_myinfra.py
Requires Python 3.9 or later. Tests must run on or have network access to the target servers being inspected.
Verify before relying
- Whether the package supports all major configuration management tools (Salt, Ansible, Puppet, Chef) equally or has gaps in any.
- Current maintenance activity and responsiveness to bug reports, given the 502-day gap since last release.
- Whether remote testing over SSH or other protocols is fully documented and production-ready.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | aging — 502 days since the last release |
| First released | |
| Downloads | 1,545,408/month — #3,779 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_testinfra-10.2.2-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
testinfraTestinfra lets you write Python unit tests that…
permissive · top 15,000 on PyPI
pytest-containerA pytest plugin that automates container…
copyleft · top 15,000 on PyPI
pytest-ansibleA pytest plugin that integrates Ansible into…
permissive · top 5,000 on PyPI
tox-ansibleA tox plugin that orchestrates testing of…
permissive · top 15,000 on PyPI
pytest-seleniumpytest-selenium is a pytest plugin that…
copyleft · top 15,000 on PyPI
pytest-instafailA pytest plugin that displays test failures and…
permissive · top 5,000 on PyPI
pytest-base-urlA pytest plugin that injects a configurable…
copyleft · top 5,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
molecule-dockerMolecule Docker Plugin enables Docker…
permissive · top 15,000 on PyPI