跳转到主要内容

测试基础设施

项目描述

最新文档:https://testinfra.readthedocs.io/en/latest

关于

使用Testinfra,您可以使用Python编写单元测试来测试由管理工具(如SaltAnsiblePuppetChef等)配置的服务器的实际状态。

Testinfra旨在成为Python中Serverspec的等效工具,并作为强大的Pytest测试引擎的插件编写。

许可证

Apache License 2.0

该标志受Creative Commons NoDerivatives 4.0 License许可。如果您有其他用途,请联系我们。

快速入门

使用pip安装testinfra

$ pip install pytest-testinfra

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

将您的第一个测试文件写入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

并运行它

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

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

pytest-testinfra-10.1.1.tar.gz (86.6 kB 查看哈希)

上传时间

构建分布

pytest_testinfra-10.1.1-py3-none-any.whl (76.8 kB 查看哈希)

上传时间 Python 3

支持者:

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面