pytest-testinfra 开源项目教程

pytest-testinfra 开源项目教程

pytest-testinfrapytest-dev/pytest-testinfra:这是一个基于Python的测试基础设施库,适合进行自动化测试和持续集成。特点包括灵活的配置、丰富的插件支持、易于编写测试用例等。项目地址:https://gitcode.com/gh_mirrors/py/pytest-testinfra

1. 项目的目录结构及介绍

pytest-testinfra 是一个用于测试基础设施的 pytest 插件。以下是其主要目录结构和介绍:

pytest-testinfra/
├── CHANGELOG.rst
├── CONTRIBUTING.rst
├── LICENSE
├── MANIFEST.in
├── README.rst
├── docs/
│   ├── conf.py
│   ├── index.rst
│   └── ...
├── pytest_testinfra/
│   ├── __init__.py
│   ├── backend/
│   │   ├── __init__.py
│   │   ├── base.py
│   │   ├── ...
│   ├── plugin.py
│   └── ...
├── setup.cfg
├── setup.py
└── tox.ini
  • CHANGELOG.rst: 项目变更日志。
  • CONTRIBUTING.rst: 贡献指南。
  • LICENSE: 项目许可证。
  • MANIFEST.in: 清单文件,用于包含或排除某些文件。
  • README.rst: 项目介绍和使用说明。
  • docs/: 项目文档目录。
    • conf.py: Sphinx 文档配置文件。
    • index.rst: 文档主页。
  • pytest_testinfra/: 项目核心代码目录。
    • __init__.py: 模块初始化文件。
    • backend/: 后端实现目录。
      • base.py: 后端基类。
    • plugin.py: pytest 插件实现。
  • setup.cfg: 安装配置文件。
  • setup.py: 安装脚本。
  • tox.ini: tox 配置文件,用于自动化测试。

2. 项目的启动文件介绍

pytest-testinfra 的启动文件主要是 pytest_testinfra/plugin.py。这个文件定义了 pytest 插件的核心功能,包括如何加载和运行测试。

# pytest_testinfra/plugin.py

import pytest
from . import backend

def pytest_addoption(parser):
    group = parser.getgroup("testinfra")
    group.addoption("--connection", action="store", default="ssh", help="Connection type to use")
    group.addoption("--hosts", action="store", default=None, help="Hosts to connect to")
    # 其他选项...

def pytest_configure(config):
    config.addinivalue_line("markers", "testinfra: mark a test as a testinfra test.")
    backend_class = backend.get_backend_class(config.getoption("--connection"))
    hosts = config.getoption("--hosts")
    # 其他配置...

# 其他功能...
  • pytest_addoption: 添加命令行选项,如连接类型和主机。
  • pytest_configure: 配置 pytest,加载后端类和主机信息。

3. 项目的配置文件介绍

pytest-testinfra 的配置文件主要是 setup.cfgtox.ini

setup.cfg

setup.cfg 是一个标准的 Python 包配置文件,用于定义包的元数据和安装选项。

[metadata]
name = pytest-testinfra
version = attr: pytest_testinfra.__version__
description = Testinfra test your infrastructures
long_description = file: README.rst, CHANGELOG.rst
license = MIT
author = Philippe Pepiot
author_email = phil@philpep.org
url = https://github.com/pytest-dev/pytest-testinfra
classifiers =
    Development Status :: 5 - Production/Stable
    Intended Audience :: Developers
    License :: OSI Approved :: MIT License
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3.6
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9

[options]
packages = find:
install_requires =
    pytest>=3.0
    paramiko
    salt
    ansible
    docker
    kubernetes

[options.extras_require]
doc =
    sphinx
    sphinx_rtd_theme

[tool:pytest]
addopts = --strict-markers
testpaths = tests

pytest-testinfrapytest-dev/pytest-testinfra:这是一个基于Python的测试基础设施库,适合进行自动化测试和持续集成。特点包括灵活的配置、丰富的插件支持、易于编写测试用例等。项目地址:https://gitcode.com/gh_mirrors/py/pytest-testinfra

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

曹艺程Luminous

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值