英文:
How to fail an azur devOps pipeline on coverage fail?
问题
我正在使用Microsoft DevOps Forge构建我的流水线。如果覆盖率低于80%,我想让测试流水线失败,但我在Microsoft文档中找不到相关信息。
这是我的test.yaml文件:
trigger:
branches:
include:
- main
pool:
vmImage: windows-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "3.10"
displayName: "使用Python 3.10"
- script: python -m pip install toto pytest pytest-cov pytest-deadfixtures
displayName: "安装依赖项"
- script: pytest --color=yes --cov --cov-report=html
displayName: "使用pytest进行测试"
英文:
I'm building my pipelines in the Microsoft dev Ops forge. I would like to make the test pipeline to fail if the coverage is < 80% but I don't find the information in the microsoft documentation.
Here is my test.yaml file:
trigger:
branches:
include:
- main
pool:
vmImage: windows-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "3.10"
displayName: "Use Python 3.10"
- script: python -m pip install toto pytest pytest-cov pytest-deadfixtures
displayName: "Install dependencies"
- script: pytest --color=yes --cov --cov-report=html
displayName: "Test with pytest"
答案1
得分: 0
你应该切换到term
输出:
- bash: |
OUTPUT=$(pytest --color=yes --cov --cov-report=term | grep 'TOTAL' | awk '{print $(NF)}')
echo $OUTPUT
COVERAGE="${OUTPUT%\%}" # 删除百分号
if (( COVERAGE < 80 )); then
echo "代码覆盖率低于80%";
exit 1;
else
echo "代码覆盖率为 $COVERAGE%";
fi
displayName: '运行 pytest'
英文:
You should switch to term
output:
- bash: |
OUTPUT=$(pytest --color=yes --cov --cov-report=term | grep 'TOTAL' | awk '{print $(NF)}')
echo $OUTPUT
COVERAGE="${OUTPUT%\%}" # Remove the percent sign
if (( COVERAGE < 80 )); then
echo "Code coverage is below 80%";
exit 1;
else
echo "Code coverage is $COVERAGE%";
fi
displayName: 'Run pytest'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论