コンテンツへスキップ

testinfra サンプル

$ more test_service2.py
import pytest

@pytest.mark.parametrize("name,version", [
    ("httpd","2.2.5"),
    ("python", "2.9"),
])

def test_packages(host, name, version):
    pkg = host.package(name)
    assert pkg.is_installed
    assert pkg.version.startsith(version)

@pytest.mark.parametrize("name", [
    ("httpd"),
    ("chronyd"),
])
def test_service(host, name):
    service = host.service(name)
    assert service.is_running

実行結果

$ py.test -v ./test_service2.py
/usr/local/lib/python3.6/site-packages/testinfra-6.0.0-py3.6.egg/_testinfra_renamed.py:10: DeprecationWarning: testinfra package has been renamed to pytest-testinfra. Please `pip install pytest-testinfra` and `pip uninstall testinfra` and update your package requirements to avoid this message
============================================================================= test session starts =============================================================================
platform linux -- Python 3.6.8, pytest-6.2.4, py-1.10.0, pluggy-1.0.0.dev0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/user1
plugins: testinfra-6.0.0, testinfra-6.3.0
collected 4 items

test_service2.py::test_packages[local-httpd-2.2.5] PASSED                                                                                                               [ 25%]
test_service2.py::test_packages[local-python-2.9] PASSED                                                                                                                [ 50%]
test_service2.py::test_service[local-httpd] PASSED                                                                                                                      [ 75%]
test_service2.py::test_service[local-chronyd] PASSED                                                                                                                    [100%]

============================================================================== 4 passed in 0.68s ==============================================================================