--- id: pytest-testinfra version: "10.2.2" license: unclear license_treatment: permissive maintenance: aging --- # pytest-testinfra — Test infrastructures License: permissive · Maintenance: aging · Downloads: 1.5M/mo ## 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 above — 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 pip install pytest-testinfra uv add pytest-testinfra poetry add pytest-testinfra ## Installing 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_current - Install friction: low - Maintenance: aging - Downloads: 1.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags infrastructure testing python, server state verification, pytest infrastructure tests, ansible puppet chef testing, configuration management validation, infrastructure as code testing, system state assertions, infrastructure-testing, configuration-management, server-validation [View on SkillFed](https://skillfed.io/packages/pytest-testinfra) · [View on PyPI](https://pypi.org/project/pytest-testinfra/)