Skip to content

CarstenGrohmann/pytest-testinfra

This branch is up to date with pytest-dev/pytest-testinfra:main.

Folders and files

NameName
Last commit message
Last commit date
Feb 15, 2024
Nov 13, 2023
May 26, 2024
Oct 21, 2024
Oct 21, 2024
Oct 31, 2019
Dec 25, 2022
Mar 8, 2016
Jul 22, 2023
May 26, 2023
May 26, 2024
May 19, 2023
Dec 25, 2022
May 19, 2023
Nov 30, 2015
Dec 25, 2022
Jan 23, 2016
Aug 24, 2023
Jul 21, 2023
Dec 25, 2022
Feb 15, 2024
Sep 18, 2021
May 21, 2023
May 19, 2023

Repository files navigation

Testinfra test your infrastructure

Latest documentation: https://testinfra.readthedocs.io/en/latest

About

With Testinfra you can write unit tests in Python to test actual state of your servers configured by management tools like Salt, Ansible, Puppet, Chef and so on.

Testinfra aims to be a Serverspec equivalent in python and is written as a plugin to the powerful Pytest test engine

License

Apache License 2.0

The logo is licensed under the Creative Commons NoDerivatives 4.0 License If you have some other use in mind, contact us.

Quick start

Install testinfra using pip:

$ pip install pytest-testinfra

# or install the devel version
$ pip install 'git+https://github.com/pytest-dev/pytest-testinfra@main#egg=pytest-testinfra'

Write your first tests file to test_myinfra.py:

def test_passwd_file(host):
    passwd = host.file("/etc/passwd")
    assert passwd.contains("root")
    assert passwd.user == "root"
    assert passwd.group == "root"
    assert passwd.mode == 0o644


def test_nginx_is_installed(host):
    nginx = host.package("nginx")
    assert nginx.is_installed
    assert nginx.version.startswith("1.2")


def test_nginx_running_and_enabled(host):
    nginx = host.service("nginx")
    assert nginx.is_running
    assert nginx.is_enabled

And run it:

$ py.test -v test_myinfra.py


====================== test session starts ======================
platform linux -- Python 2.7.3 -- py-1.4.26 -- pytest-2.6.4
plugins: testinfra
collected 3 items

test_myinfra.py::test_passwd_file[local] PASSED
test_myinfra.py::test_nginx_is_installed[local] PASSED
test_myinfra.py::test_nginx_running_and_enabled[local] PASSED

=================== 3 passed in 0.66 seconds ====================

About

Testinfra test your infrastructures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.0%
  • Dockerfile 2.0%