Testinfra

Testinfra 为您测试基础设施。「Testinfra test your infrastructures」

Github星跟踪图

##################################
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 <https://github.com/pytest-dev/pytest-testinfra/blob/main/LICENSE>_

The logo is licensed under the Creative Commons NoDerivatives 4.0 License <https://creativecommons.org/licenses/by-nd/4.0/>_
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:

.. code-block:: python

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

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

主要指标

概览
名称与所有者pytest-dev/pytest-testinfra
主编程语言Python
编程语言Python (语言数: 3)
平台
许可证Apache License 2.0
所有者活动
创建于2015-03-15 20:49:52
推送于2025-04-01 19:19:03
最后一次提交
发布数90
最新版本名称10.2.2 (发布于 )
第一版名称1.0.0 (发布于 2016-01-22 14:05:50)
用户参与
星数2.4k
关注者数68
派生数361
提交数814
已启用问题?
问题数359
打开的问题数130
拉请求数335
打开的拉请求数17
关闭的拉请求数97
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?