Skip to content
Snippets Groups Projects
Commit 4fb81f8b authored by Clement Bois's avatar Clement Bois Committed by Pierre Smeyers
Browse files

fix(test): handle decimal coverage

- adapt the regex that captures the coverage value
- add a root job prototype for all unit test jobs
parent 75183d22
No related branches found
No related tags found
No related merge requests found
...@@ -955,7 +955,7 @@ stages: ...@@ -955,7 +955,7 @@ stages:
- production - production
############################################################################################### ###############################################################################################
# Generic python job # # Generic python jobs #
############################################################################################### ###############################################################################################
.python-base: .python-base:
image: $PYTHON_IMAGE image: $PYTHON_IMAGE
...@@ -980,6 +980,25 @@ stages: ...@@ -980,6 +980,25 @@ stages:
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}" - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
- cd ${PYTHON_PROJECT_DIR} - cd ${PYTHON_PROJECT_DIR}
- guess_build_system - guess_build_system
- mkdir -p -m 777 reports
.python-test:
extends: .python-base
stage: build
coverage: /^TOTAL.+?(\d+(?:\.\d+)?\%)$/
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
junit:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
coverage_report:
coverage_format: cobertura
path: "$PYTHON_PROJECT_DIR/reports/py-coverage.cobertura.xml"
paths:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
- "$PYTHON_PROJECT_DIR/reports/py-coverage.*"
############################################################################################### ###############################################################################################
# build stage # # build stage #
...@@ -1001,7 +1020,6 @@ py-lint: ...@@ -1001,7 +1020,6 @@ py-lint:
extends: .python-base extends: .python-base
stage: build stage: build
script: script:
- mkdir -p -m 777 reports
- install_requirements - install_requirements
- _pip install pylint_gitlab # codeclimate reports - _pip install pylint_gitlab # codeclimate reports
# run pylint and generate reports all at once # run pylint and generate reports all at once
...@@ -1062,7 +1080,6 @@ py-ruff: ...@@ -1062,7 +1080,6 @@ py-ruff:
extends: .python-base extends: .python-base
stage: build stage: build
script: script:
- mkdir -p -m 777 reports
- | - |
if [[ ${BANDIT_ENABLED} == "true" || ${PYLINT_ENABLED} == "true" || ${PYTHON_ISORT_ENABLED} == "true" ]]; then if [[ ${BANDIT_ENABLED} == "true" || ${PYLINT_ENABLED} == "true" || ${PYTHON_ISORT_ENABLED} == "true" ]]; then
log_warn "Ruff can replace isort, Bandit, Pylint" log_warn "Ruff can replace isort, Bandit, Pylint"
...@@ -1095,7 +1112,6 @@ py-ruff-format: ...@@ -1095,7 +1112,6 @@ py-ruff-format:
extends: .python-base extends: .python-base
stage: build stage: build
script: script:
- mkdir -p -m 777 reports
- | - |
if [[ ${PYTHON_BLACK_ENABLED} == "true" ]]; then if [[ ${PYTHON_BLACK_ENABLED} == "true" ]]; then
log_warn "Ruff can replace Black" log_warn "Ruff can replace Black"
...@@ -1115,7 +1131,6 @@ py-mypy: ...@@ -1115,7 +1131,6 @@ py-mypy:
variables: variables:
MYPY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/mypy" MYPY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/mypy"
script: script:
- mkdir -p -m 777 reports
- install_requirements - install_requirements
- _pip install mypy mypy-to-codeclimate - _pip install mypy mypy-to-codeclimate
- _run mypy ${MYPY_ARGS} ${MYPY_FILES:-$(find -type f -name "*.py" -not -path "./.cache/*" -not -path "./.venv/*")} | tee reports/py-mypy.console.txt || true - _run mypy ${MYPY_ARGS} ${MYPY_FILES:-$(find -type f -name "*.py" -not -path "./.cache/*" -not -path "./.venv/*")} | tee reports/py-mypy.console.txt || true
...@@ -1139,10 +1154,8 @@ py-mypy: ...@@ -1139,10 +1154,8 @@ py-mypy:
# test stage # # test stage #
############################################################################################### ###############################################################################################
py-unittest: py-unittest:
extends: .python-base extends: .python-test
stage: build
script: script:
- mkdir -p -m 777 reports
- install_requirements - install_requirements
# code coverage # code coverage
- _pip install coverage - _pip install coverage
...@@ -1151,20 +1164,6 @@ py-unittest: ...@@ -1151,20 +1164,6 @@ py-unittest:
- _run coverage run -m xmlrunner discover -o "reports/" $UNITTEST_ARGS - _run coverage run -m xmlrunner discover -o "reports/" $UNITTEST_ARGS
- _run coverage report -m - _run coverage report -m
- _run coverage xml -o "reports/py-coverage.cobertura.xml" - _run coverage xml -o "reports/py-coverage.cobertura.xml"
coverage: /^TOTAL.+?(\d+\%)$/
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
junit:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
coverage_report:
coverage_format: cobertura
path: "$PYTHON_PROJECT_DIR/reports/py-coverage.cobertura.xml"
paths:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
- "$PYTHON_PROJECT_DIR/reports/py-coverage.*"
rules: rules:
# skip if $UNITTEST_ENABLED not set # skip if $UNITTEST_ENABLED not set
- if: '$UNITTEST_ENABLED != "true"' - if: '$UNITTEST_ENABLED != "true"'
...@@ -1172,27 +1171,11 @@ py-unittest: ...@@ -1172,27 +1171,11 @@ py-unittest:
- !reference [.test-policy, rules] - !reference [.test-policy, rules]
py-pytest: py-pytest:
extends: .python-base extends: .python-test
stage: build
script: script:
- mkdir -p -m 777 reports
- install_requirements - install_requirements
- _pip install pytest pytest-cov coverage - _pip install pytest pytest-cov coverage
- _python -m pytest --junit-xml=reports/TEST-pytests.xml --cov --cov-report term --cov-report xml:reports/py-coverage.cobertura.xml ${PYTEST_ARGS} - _python -m pytest --junit-xml=reports/TEST-pytests.xml --cov --cov-report term --cov-report xml:reports/py-coverage.cobertura.xml ${PYTEST_ARGS}
coverage: /^TOTAL.+?(\d+\%)$/
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
junit:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
coverage_report:
coverage_format: cobertura
path: "$PYTHON_PROJECT_DIR/reports/py-coverage.cobertura.xml"
paths:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
- "$PYTHON_PROJECT_DIR/reports/py-coverage.*"
rules: rules:
# skip if $PYTEST_ENABLED not set # skip if $PYTEST_ENABLED not set
- if: '$PYTEST_ENABLED != "true"' - if: '$PYTEST_ENABLED != "true"'
...@@ -1200,26 +1183,10 @@ py-pytest: ...@@ -1200,26 +1183,10 @@ py-pytest:
- !reference [.test-policy, rules] - !reference [.test-policy, rules]
py-nosetests: py-nosetests:
extends: .python-base extends: .python-test
stage: build
script: script:
- mkdir -p -m 777 reports
- install_requirements - install_requirements
- _run nosetests --with-xunit --xunit-file=reports/TEST-nosetests.xml --with-coverage --cover-erase --cover-xml --cover-xml-file=reports/py-coverage.cobertura.xml ${NOSETESTS_ARGS} - _run nosetests --with-xunit --xunit-file=reports/TEST-nosetests.xml --with-coverage --cover-erase --cover-xml --cover-xml-file=reports/py-coverage.cobertura.xml ${NOSETESTS_ARGS}
coverage: /^TOTAL.+?(\d+\%)$/
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
junit:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
coverage_report:
coverage_format: cobertura
path: "$PYTHON_PROJECT_DIR/reports/py-coverage.cobertura.xml"
paths:
- "$PYTHON_PROJECT_DIR/reports/TEST-*.xml"
- "$PYTHON_PROJECT_DIR/reports/py-coverage.*"
rules: rules:
# skip if $NOSETESTS_ENABLED not set # skip if $NOSETESTS_ENABLED not set
- if: '$NOSETESTS_ENABLED != "true"' - if: '$NOSETESTS_ENABLED != "true"'
...@@ -1233,7 +1200,6 @@ py-bandit: ...@@ -1233,7 +1200,6 @@ py-bandit:
# force no dependencies # force no dependencies
dependencies: [] dependencies: []
script: script:
- mkdir -p -m 777 reports
- install_requirements - install_requirements
- _pip install bandit - _pip install bandit
# CSV (for SonarQube) # CSV (for SonarQube)
...@@ -1269,7 +1235,6 @@ py-trivy: ...@@ -1269,7 +1235,6 @@ py-trivy:
# force no dependencies # force no dependencies
dependencies: [] dependencies: []
script: script:
- mkdir -p -m 777 reports
- | - |
if [[ -z "$PYTHON_TRIVY_DIST_URL" ]] if [[ -z "$PYTHON_TRIVY_DIST_URL" ]]
then then
...@@ -1348,7 +1313,6 @@ py-sbom: ...@@ -1348,7 +1313,6 @@ py-sbom:
dependencies: [] dependencies: []
needs: [] needs: []
script: script:
- mkdir -p -m 777 reports
- | - |
case "$PYTHON_BUILD_SYSTEM" in case "$PYTHON_BUILD_SYSTEM" in
poetry*|pipenv*) poetry*|pipenv*)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment