#2735: pipeline build fail if test fails
This commit is contained in:
@@ -102,9 +102,7 @@ stages:
|
|||||||
version: '2.1.x'
|
version: '2.1.x'
|
||||||
|
|
||||||
- script: |
|
- script: |
|
||||||
coverage run -m --source=primaite pytest -v -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov-fail-under=80
|
python run_test_and_coverage.py
|
||||||
coverage xml -o coverage.xml -i
|
|
||||||
coverage html -d htmlcov -i
|
|
||||||
displayName: 'Run tests and code coverage'
|
displayName: 'Run tests and code coverage'
|
||||||
|
|
||||||
# Run the notebooks
|
# Run the notebooks
|
||||||
|
|||||||
22
run_test_and_coverage.py
Normal file
22
run_test_and_coverage.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def run_command(command: Any):
|
||||||
|
"""Runs a command and returns the exit code."""
|
||||||
|
result = subprocess.run(command, shell=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
sys.exit(result.returncode)
|
||||||
|
|
||||||
|
|
||||||
|
# Run pytest with coverage
|
||||||
|
run_command(
|
||||||
|
"coverage run -m --source=primaite pytest -v -o junit_family=xunit2 "
|
||||||
|
"--junitxml=junit/test-results.xml --cov-fail-under=80"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate coverage reports if tests passed
|
||||||
|
run_command("coverage xml -o coverage.xml -i")
|
||||||
|
run_command("coverage html -d htmlcov -i")
|
||||||
Reference in New Issue
Block a user