Testinfra test your infrastructures
Перейти к файлу
Daniel Hobley 58fa564f0a Added passing of kwargs to local commands 2017-04-27 10:16:54 +02:00
doc modules: dynamic import 2017-03-26 20:34:58 +02:00
images Sudo: restore backend command in case of exceptions 2017-01-26 14:20:05 +01:00
testinfra Added passing of kwargs to local commands 2017-04-27 10:16:54 +02:00
.gitignore Tests with docker-compose 2016-03-08 21:14:13 +01:00
.travis.yml tests: remove notes about pulling images 2016-06-26 02:07:54 +02:00
CHANGELOG.rst update changelog for 1.5.5 2017-04-13 14:21:50 +02:00
CONTRIBUTING.rst Convert readthedocs links for their .org -> .io migration for hosted projects 2016-10-12 23:08:16 +01:00
LICENSE dont put the license under license 2016-05-15 01:43:26 +02:00
Makefile Makefile cleanup 2015-11-30 18:02:09 +01:00
README.rst Convert readthedocs links for their .org -> .io migration for hosted projects 2016-10-12 23:08:16 +01:00
ansible.cfg Fix tests on travis 2016-01-23 17:26:04 +01:00
dev-requirements.txt doc: Fix readthedocs build 2015-05-27 13:50:35 +02:00
pylintrc pylint: dont check max line length 2016-05-15 14:35:59 +02:00
requirements.txt [pkg] add dependency on importlib for python 2.6 (#172) 2016-12-29 19:48:00 +01:00
setup.cfg [pkg] skip pbr author and changelog generation 2016-12-04 18:36:26 +01:00
setup.py normalize the license header and coding directive 2016-05-15 01:50:07 +02:00
test-requirements.txt backends: dynamic import 2016-12-14 23:40:41 +01:00
tox.ini update changelog for 1.5.5 2017-04-13 14:21:50 +02:00

README.rst

##################################
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 managements 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

Quick start
===========

Install testinfra using pip::

    $ pip install testinfra

    # or install the devel version
    $ pip install 'git+https://github.com/philpep/testinfra@master#egg=testinfra'


Write your first tests file to `test_myinfra.py`::

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


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


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


And run it::

    $ testinfra -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 ====================


.. _Salt: http://saltstack.com/
.. _Ansible: http://www.ansible.com/
.. _Puppet: https://puppetlabs.com/
.. _Chef: https://www.chef.io/
.. _Serverspec: http://serverspec.org/
.. _Pytest: http://pytest.org