[英]Running Azure DevOps pipeline exists with ##[error]Bash exited with code '1'
Introduction:介绍:
I created a simple add function to get more insight in how Azure Dev Ops is working.我创建了一个简单的添加 function 以更深入地了解 Azure Dev Ops 的工作方式。 When I let test_method2() fail on purpose the pipeline exists with ##[error]Bash exited with code '1'.
当我故意让 test_method2() 失败时,管道存在,##[error]Bash 以代码“1”退出。 Therefore in Azure Dev Ops an overview of Tests (which ones are fine and which ones are not) and Code Coverage is missing.
因此,在 Azure Dev Ops 中对测试进行了概述(哪些很好,哪些不是)并且缺少代码覆盖率。 I would expect that overview Test and Code Coverage is still provided in case of a failing test.
我希望在测试失败的情况下仍然提供概述测试和代码覆盖率。 To summarize, it's fine that a test fails but this should be reported and the process should not be stopped.
总而言之,测试失败很好,但应该报告并且不应该停止该过程。
Note that when I repair the test, ie 'def test_method2(): assert add(15,5) == 20 ' the pipeline works as expected.请注意,当我修复测试时,即 'def test_method2(): assert add(15,5) == 20 ' 管道按预期工作。
My question is what is needed to make sure that overview of Tests and Code Coverage is still provided in case of failing tests?我的问题是需要什么来确保在测试失败的情况下仍然提供测试和代码覆盖率的概述?
calc_lean.py: calc_lean.py:
def add(x, y):
"""Add Function"""
return x + y
test_calc_lean.py: test_calc_lean.py:
import pytest
from calc_lean import add
def test_method1():
assert add(3,5) == 8
def test_method2():
assert add(15,5) == 21
azure-pipelines.yml: azure-pipelines.yml:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
strategy:
matrix:
Python37:
python.version: '3.7'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
displayName: 'Install dependencies'
- script: |
pip install pytest
pip install pytest-cov
pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml
displayName: pytest
- task: PublishTestResults@2
displayName: 'Publish Test Results **/test-results.xml'
inputs:
testResultsFiles: '**/test-results.xml'
testRunTitle: 'Python $(python.version)'
- task: PublishCodeCoverageResults@1
displayName: 'Code Coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
Solution: Problem was already discussed in other posts.解决方案:问题已经在其他帖子中讨论过了。 Amongst others Failed Cypress test exit in 'bash exited with code 1' in Azure DevOps
Azure DevOps 中的“bash exited with code 1”中的 Cypress 测试退出失败
Adding ' ||添加'|| true' adressed it.
真的'解决了它。 That is,
那是,
pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml || true
supresses the err抑制错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.