pytest插件,用于在ansible集合中运行单元测试
项目描述
pytest-ansible-units
一个实验性的pytest
插件,用于使用pytest
运行ansible集合的单元测试。
描述
pytest-ansible-units
是一个pytest
插件,允许使用仅pytest
运行ansible集合的单元测试。pytest
可以从命令行或IDE中使用。
入门
依赖关系
安装pytest-ansible-units
将安装以下内容
pytest
pytest-ansible-units
需要Python 3.8或更高版本,ansible-core和pyyaml。
安装
python -m pip install pytest-ansible-units
需要安装 ansible-core
和 pyyaml
来激活插件。
支持两种目录结构,任选其一都需要安装集合依赖。可以在默认用户位置或在选项 1 中的集合树结构中安装。
集合树
首选方法是将其正在开发的集合克隆到适当的集合树路径。这消除了对任何符号链接的需求,并且可以将在同一树结构中克隆正在开发的其它集合。
git clone <repo> collections/ansible_collections/<namespace>/<name>
注意
pytest
需要在集合目录的根目录中运行,紧邻集合的 galaxy.yml 文件。
浅树结构
另一种方法是允许浅目录结构。
git clone <repo>
注意
pytest
需要在集合目录的根目录中运行,紧邻集合的 galaxy.yml 文件。- 在存储库目录中创建一个集合目录,并将集合内容链接到其中。
- 将
/collections/
添加到 .gitignore 中,因为不需要将其提交。 - 使用这种方法,由于符号链接,
ansible-test sanity
将失败。
执行程序
从命令行,从集合的根目录
pytest tests
帮助
可以将以下内容添加到集合的 pyproject.toml
文件中,以限制警告并设置集合测试的默认路径
[tool.pytest.ini_options]
testpaths = [
"tests",
]
filterwarnings = [
'ignore:AnsibleCollectionFinder has already been configured',
]
galaxy.yml
文件中的信息用于构建 collections
目录结构并链接内容。galaxy.yml
文件应反映正确的集合命名空间和名称。
在不运行测试的情况下检测问题的方法之一是运行
pytest --collect-only
可能会看到以下错误
E ModuleNotFoundError: No module named 'ansible_collections'
- 检查
galaxy.yml
文件以确保命名空间和名称准确 - 确保
pytest
是从集合的根目录运行的,紧邻galaxy.yml
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
- 确保每个测试目录都有一个
__init__.py
作者
- cidrblock
许可证
本项目采用 GPL-v3 许可证 - 请参阅 LICENSE 文件获取详细信息
项目详情
关闭
pytest-ansible-units-0.1.dev50.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 121a76284a0b5c5889c66c88610ff2a38724465ca5d5c801196eea85be369801 |
|
MD5 | 5404d6ae82903945aeae9759b61f4758 |
|
BLAKE2b-256 | afea20b98f36f839e9dcbea833042d641ca91d8b2da8bbc8c98ae2e33de84ca8 |