pytest-testinfra is a popular infrastructure testing framework that extends pytest with fixtures for verifying remote and local server state. It supports multiple backends (SSH, Docker, Ansible, Salt, Kubernetes, local) and provides modules for files, packages, services, processes, and more. The latest stable version on PyPI is 6.0.0, but the GitHub project is actively developed at v10.2.2. The project has seen breaking changes in recent major versions, including dropping Python 3.7 and 3.8 support, and renaming modules. Release cadence is irregular, with major versions every 1-2 years.
pip install pytest-testinfraVerified import paths — ran on the pinned version, not inferred.
Basic test using the host fixture. Run with: pytest --hosts='ssh://user@host' test_file.py
Upgrade to pytest-testinfra >=9.0.0 and use Python >=3.9.
Replace `PipPackage` with `host.run('pip list')` or iterate `host.pip_package.get_packages()`.Define test functions with a parameter named `host` and run pytest with the plugin loaded.
Review tests that rely on `service.exists` for services that may not be available.