Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< 返回工具列表
P

pytest-testinfra

> DevOps
开源

Testinfra test your infrastructures

2.5K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Testinfra test your infrastructures

################################## Testinfra test your infrastructure ##################################

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

.. important::

Maintenance Notice

This project is currently not actively maintained, and responses to issues or pull requests may be delayed for several months. Please consider this when using the project and feel free to contribute via pull requests, which will be reviewed as time permits. Thank you for your understanding!

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

$ pytest -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/

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

  • •Python
  • •ansible
  • •chef
  • •devops
  • •devops-tools

> 标签

Pythonansiblechefdevopsdevops-tools

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理