为azure管道ui格式化pytest输出
pytest-azurepipelines的Python项目详细描述
使pytest更易于与microsoft azure管道一起使用。
只需使用这个插件运行pytest,并在azure管道ui中查看测试结果!
功能:
- 将pytest输出格式化为在azure管道ui中显示测试文档字符串和模块名称,而不仅仅是测试用例名称。
- 使用默认值重载执行时的JUnit XML标志
- 自动上载测试结果,不需要单独的测试结果上载命令
- 如果在用户界面中出现错误消息,则显示失败的测试数
- 如果安装了pytest cov,则自动格式化代码覆盖率并上载覆盖率数据
- 支持在Docker容器内运行并自动上载测试结果
用法
此插件不需要配置。
下面是安装插件并运行测试的示例。
-script:|python -m pip install --upgrade pippip install pytest pytest-azurepipelinespip install -e .displayName:'Installdependencies'-script:|python -m pytest tests/displayName:'pytest'
如果要更改azure管道“测试运行标题”,可以提供带有运行标题的–测试运行标题标志。
-script:|pip install pytest pytest-azurepipelinespytest tests/ --test-run-title="Windows Test with junitxml"displayName:'pytestwithjunitxmlflag'
如果您的函数中有长docstrings并希望将其缩短,则可以使用–napoleon docstrings标志:
-script:|pip install pytest pytest-azurepipelinespytest tests/ --test-run-title="Windows Test with junitxml" --napoleon-docstrings
使用自动代码覆盖率上载
从0.6.0版开始,pytest将成功地将覆盖率数据上传到azure支持的格式中并打包 将htmlcov目录作为构建的工件放入zip文件中。
要使用此功能,请将带有(可选但必需)路径的–cov标记添加到代码文件中,并确保将–cov report html添加为选项。
-script:|pip install pytest pytest-azurepipelines pytest-covpytest tests/ --cov my_project --cov-report html
要禁用覆盖率上载,请使用–no coverage upload标志。
在Docker中运行
插件在Docker中运行时自动检测 集装箱。它将适用 使用路径将它们报告回azure管道的路径映射 从已绑定到Docker容器的主机。
如果绑定安装是 用于pytest输出写入的路径。同时确保文件 使用主机有权访问的帐户编写,这可以通过提供 运行命令的主机帐户的用户和组。
docker run --user "$(id -u):$(id -g)" ...
要禁用docker discovery,请使用–no docker discovery标志。
贡献
我们非常欢迎您的贡献。
许可证
“Pytest AzurePipelines”是根据麻省理工学院许可证条款发行的免费开源软件
问题
如果您遇到任何问题,请file an issue连同详细说明。