Registry / testing / pytest-testinfra

pytest-testinfra

JSON →
library10.2.2pypypi✓ verified 24d ago

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-testinfra
INSTALL
IMPORT
SIG · PYTEST-TESTINFRA
P
pytest-testinfra
testingpythonv10.2.2
Install
2.9s avg
Import
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v10.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 31.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.9s · import 0.000s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

host
def test_something(host):
from testinfra import host
host is a pytest fixture, not a direct import.

Basic test using the host fixture. Run with: pytest --hosts='ssh://user@host' test_file.py

import pytest def test_ssh(host): cmd = host.run('echo hello') assert cmd.rc == 0 assert 'hello' in cmd.stdout
Debug
Known issues
breakingPython 3.7 support dropped in v8.0.0, Python 3.8 dropped in v9.0.0. Use Python >=3.9.
fix
Upgrade to pytest-testinfra >=9.0.0 and use Python >=3.9.
affects: <9.0.0
deprecatedThe `PipPackage` module was removed in v9.0.0. Use `PipPackage.get_packages()` or the `pip` command.
fix
Replace `PipPackage` with `host.run('pip list')` or iterate `host.pip_package.get_packages()`.
affects: <9.0.0
gotchaThe `host` fixture is not imported; it is a pytest fixture provided by the plugin. Direct imports like `from testinfra import host` will fail.
fix
Define test functions with a parameter named `host` and run pytest with the plugin loaded.
affects: all
breakingBreaking change in v10.0.0: The `exists` property on `Service` was fixed to actually check service existence; previously it might return inaccurate results.
fix
Review tests that rely on `service.exists` for services that may not be available.
affects: >=10.0.0
Upgrade
Version history
10.2.2latest on PyPI · released Mar 30, 2025
Audit
Dependencies
pytestrequiredpytest-testinfra is a pytest plugin and requires pytest to run.
paramikooptionalRequired for SSH backend connections.
Agent activity
10 hits · last 30 days
node
8
Resources
pytest-testinfra — pip install pytest-testinfra · libregistry