testinfra
Test infrastructures
What it is and what it does
Testinfra is a pytest plugin that lets you write Python unit tests to verify the actual state of servers and infrastructure. Instead of testing code in isolation, you write assertions about real system state—whether files exist with the right permissions, packages are installed, services are running, and configuration is correct. It's designed as a Python equivalent to Serverspec and works with infrastructure-as-code tools like Ansible, Puppet, Chef, and Salt.
You write tests using a `host` fixture that provides methods to inspect files, packages, services, users, and other system resources. Tests run through pytest, so you get all the standard pytest features and reporting. The project is currently not actively maintained, with the latest release over 5 years old and a maintenance notice warning that responses to issues may be delayed for several months.
Use it for:
- Verify that Ansible or Puppet playbooks correctly configured servers after deployment.
- Test that required packages are installed and services are running on production systems.
- Check file permissions, ownership, and content match infrastructure requirements.
- Validate system configuration (users, groups, network settings) in automated pipelines.
- Ensure compliance with security baselines by asserting expected system state.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Testinfra lets you write Python unit tests that verify the actual state of servers—checking files, packages, services, and system configuration—as a pytest plugin.
Yes, if you need to test infrastructure state and can accept the maintenance risk. The package is stable and has no known vulnerabilities, but the lack of active maintenance means you may need to fork or patch it yourself if issues arise. It's well-suited for teams already using pytest and infrastructure-as-code tools, but consider whether a maintained alternative better fits your long-term needs.
Install
testinfra on PyPI
pip
pip install testinfrauv
uv add testinfrapoetry
poetry add testinfraInstalling testinfra
Before you install
Low friction install with a single runtime dependency (pytest). However, the project is not actively maintained; the latest release was over 5 years ago, and the description explicitly warns that issue and pull request responses may be delayed for several months.
License in practice
Licensed under Apache License 2.0 (permissive), so you can use it freely in commercial and open-source projects without restrictive obligations.
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.5 or later; tests run against actual servers or local system, so the target infrastructure must be accessible.
Verify before relying
- Whether the project accepts and merges community pull requests despite the maintenance notice.
- Current compatibility with modern versions of pytest and Python 3.9+.
- Whether there are maintained forks or alternative projects that provide similar functionality.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest-testinfra |
| Maintenance | actively maintained — 2,101 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 141,218/month — #11,245 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: testinfra-6.0.0-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
pytest-testinfraA pytest plugin that lets you write Python unit…
permissive · top 5,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-instafailA pytest plugin that displays test failures and…
permissive · top 5,000 on PyPI
pytest-seleniumpytest-selenium is a pytest plugin that…
copyleft · top 15,000 on PyPI
molecule-dockerMolecule Docker Plugin enables Docker…
permissive · top 15,000 on PyPI
moleculeMolecule is an Ansible testing framework for…
permissive · top 5,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI