对Ansible内容测试的激进方法
项目描述
tox-ansible
介绍
tox-ansible
是一个旨在简化Ansible内容集合测试的实用工具。
作为tox
插件实现,tox-ansible
提供了一种简单的方法,在多个Python解释器和Ansible版本之间测试Ansible内容集合。
tox-ansible
使用熟悉的python测试工具执行实际测试。它使用tox
创建和管理测试环境,使用ansible-test sanity
运行健全性测试,使用pytest
运行单元和集成测试。这消除了其他方法中的黑盒性质,并允许对测试过程有更多的控制。
在本地开发系统上使用时,每个环境在测试运行后都保持完好。这使得针对给定测试类型、Python解释器和Ansible版本轻松调试失败的测试变得容易。
通过使用 tox
创建和管理测试环境,本地开发系统上的测试结果应该始终与 CI/CD 管道中的结果相同。
tox
虚拟环境在 .tox
目录中创建。如果需要,这些环境可以轻松删除和重建。
联系我们
需要帮助或想讨论项目?请参阅我们的 贡献指南 加入对话!
安装
从 PyPI 安装
pip install tox-ansible
用法
从您的收集根目录开始,创建一个空的 tox-ansible.ini
文件,并列出可用的环境
touch tox-ansible.ini
tox list --ansible --conf tox-ansible.ini
将显示动态生成的 Ansible 环境列表
default environments:
...
integration-py3.11-2.14 -> Integration tests for ansible.scm using ansible-core 2.14 and python 3.11
integration-py3.11-devel -> Integration tests for ansible.scm using ansible-core devel and python 3.11
integration-py3.11-milestone -> Integration tests for ansible.scm using ansible-core milestone and python 3.11
...
sanity-py3.11-2.14 -> Sanity tests for ansible.scm using ansible-core 2.14 and python 3.11
sanity-py3.11-devel -> Sanity tests for ansible.scm using ansible-core devel and python 3.11
sanity-py3.11-milestone -> Sanity tests for ansible.scm using ansible-core milestone and python 3.11
...
unit-py3.11-2.14 -> Unit tests for ansible.scm using ansible-core 2.14 and python 3.11
unit-py3.11-devel -> Unit tests for ansible.scm using ansible-core devel and python 3.11
unit-py3.11-milestone -> Unit tests for ansible.scm using ansible-core milestone and python 3.11
这些代表可用的测试环境。每个都表示将要运行的测试类型、用于运行测试的 Python 解释器和用于运行测试的 Ansible 版本。
要使用单个环境运行测试,只需运行以下命令
tox -e sanity-py3.11-2.14 --ansible --conf tox-ansible.ini
要使用多个环境运行测试,只需将环境名称添加到命令中
tox -e sanity-py3.11-2.14,unit-py3.11-2.14 --ansible --conf tox-ansible.ini
要运行所有可用环境中特定类型的所有测试,请使用 -f
标志
tox -f unit --ansible -p auto --conf tox-ansible.ini
要运行所有可用环境中的所有测试
tox --ansible -p auto --conf tox-ansible.ini
注意:-p auto
标志将并行运行多个测试。注意:需要预先在您的系统上安装特定的 Python 解释器,例如
sudo dnf install python3.10
查看每个集成、健全性和单元因素的特定命令和配置
tox config --ansible --conf tox-ansible.ini
使用 --matrix-scope
根据提到的范围生成特定的 GitHub 动作矩阵
tox --ansible --gh-matrix --matrix-scope unit --conf tox-ansible.ini
将特别显示用于单元测试的动态生成的 Ansible 环境列表
[
{
"description": "Unit tests using ansible 2.9 and python 3.8",
"factors": [
"unit",
"py3.8",
"2.9"
],
"name": "unit-py3.8-2.9",
"python": "3.8"
},
...
{
"description": "Unit tests using ansible-core milestone and python 3.12",
"factors": [
"unit",
"py3.12",
"milestone"
],
"name": "unit-py3.12-milestone",
"python": "3.12"
}
]
配置
应使用 tox-ansible.ini
文件配置 tox-ansible
。使用 tox-ansible.ini
文件允许在不冲突的情况下将 tox-ansible
插件引入到可能已有现有 tox
配置的仓库中。如果不需要配置覆盖,则 tox-ansible.ini
文件可以是空的,但应该存在。除了所有 tox
支持的关键字外,还有 ansible
部分和 skip
关键字可用
# tox-ansible.ini
[ansible]
skip =
2.9
devel
这将跳过使用 Ansible 2.9 或 devel 分支的任何环境中的测试。字符串列表用于环境名称的简单字符串与字符串比较。有关覆盖 tox-ansible
环境配置的指南,请参阅此处。
发布流程
tox-ansible
使用 CalVer 方案版本号发布。我们正在使用的特定方案是 YY.MM.MICRO
,这意味着 2025 年 3 月的发布将被命名为 25.3.0
,如果需要为该发布创建补丁(即非功能)发布,则它将被命名为 25.3.1,即使它在 4 月发布。只有在发布带有功能或其他重大更改的新版本时,月份才会增加。更多有关 calver 发布过程的详细信息,请参阅此处。
1.x 版本用户注意
tox-ansible v1 的用户应使用稳定/1.x 分支,因为默认分支是对 tox 4.0+ 插件的重新编写,与旧插件不向后兼容。
插件的 1.0 版本具有对 molecule 的原生支持。请参阅上面的“运行 molecule 场景”部分以获取替代方法。
许可证
MIT
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。