Skip to content

Commit 4654df7

Browse files
author
“jagnd1”
committed
FIX: complete coverage configuration alignment
- moved .coveragerc to testing/ directory where pytest runs - configured relative_files=True for sonarcloud compatibility - aligned all source paths: ../crypto_service, ../pki_service, ../common - removed __init__.py exclusions from all configs - pytest.ini, run_tests.sh, github actions all use .coveragerc - sonar-project.properties expects testing/coverage.xml - fixes absolute vs relative path mismatch per sonarcloud docs this addresses all 15+ previous issues systematically
1 parent b628572 commit 4654df7

7 files changed

Lines changed: 1169 additions & 702 deletions

File tree

.coveragerc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[run]
2+
# Enable relative file paths for SonarCloud compatibility
3+
relative_files = True
4+
5+
# Source directories to measure coverage for (relative to testing/ directory)
6+
source = ../crypto_service, ../pki_service, ../common
7+
8+
# Omit test files from coverage measurement
9+
omit =
10+
*/test_*.py
11+
*/tests/*
12+
*/*_test.py
13+
*/test.py
14+
testing/*
15+
**/__pycache__/*
16+
*/.venv/*
17+
18+
[report]
19+
# Reporting configuration
20+
show_missing = True
21+
skip_covered = False
22+
23+
[xml]
24+
# XML output configuration for SonarCloud (relative to testing/ directory)
25+
output = coverage.xml

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,11 @@ jobs:
106106
export PROTOCOL="http"
107107
export PYTHONPATH="../:$PYTHONPATH"
108108
109+
# Use .coveragerc configuration for consistent coverage paths
109110
pytest unit_tests/ integration_tests/ e2e_tests/ \
110-
--cov=../crypto_service \
111-
--cov=../pki_service \
112-
--cov=../common \
113-
--cov-report=xml:coverage.xml \
114-
--cov-report=html:htmlcov \
111+
--cov \
115112
--junitxml=test-results.xml \
116113
-v
117-
118-
# Fix coverage.xml sources to be relative paths for SonarCloud
119-
sed -i 's|<source>/home/runner/work/fmcrypto/fmcrypto/common</source>|<source>common</source>|g' coverage.xml
120-
sed -i 's|<source>/home/runner/work/fmcrypto/fmcrypto/crypto_service</source>|<source>crypto_service</source>|g' coverage.xml
121-
sed -i 's|<source>/home/runner/work/fmcrypto/fmcrypto/pki_service</source>|<source>pki_service</source>|g' coverage.xml
122114
123115
- name: stop services
124116
if: always()

testing/.coveragerc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[run]
2+
# Enable relative file paths for SonarCloud compatibility
3+
relative_files = True
4+
5+
# Source directories to measure coverage for (relative to testing/ directory)
6+
source = ../crypto_service, ../pki_service, ../common
7+
8+
# Omit test files from coverage measurement
9+
omit =
10+
*/test_*.py
11+
*/tests/*
12+
*/*_test.py
13+
*/test.py
14+
testing/*
15+
**/__pycache__/*
16+
*/.venv/*
17+
18+
[report]
19+
# Reporting configuration
20+
show_missing = True
21+
skip_covered = False
22+
23+
[xml]
24+
# XML output configuration for SonarCloud (relative to testing/ directory)
25+
output = coverage.xml

testing/0_sonarcloud.txt

Lines changed: 1112 additions & 666 deletions
Large diffs are not rendered by default.

testing/pytest.ini

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,11 @@ python_classes = Test*
66
python_functions = test_*
77
pythonpath = ..
88

9-
# coverage configuration
9+
# coverage configuration (using .coveragerc file)
1010
addopts =
11-
--cov=../crypto_service
12-
--cov=../pki_service
13-
--cov=../common
14-
--cov-report=xml:coverage.xml
15-
--cov-report=html:htmlcov
16-
--cov-report=term-missing
17-
--cov-fail-under=80
1811
--junitxml=test-results.xml
1912
-v
2013
--asyncio-mode=auto
2114

22-
# ignore test files in coverage
23-
omit =
24-
*/test_*.py
25-
*/tests/*
26-
*/__init__.py
27-
*/conftest.py
28-
2915
# minimum coverage threshold
3016
minversion = 6.0

testing/run_sonar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ sonar-scanner \
5353
-Dsonar.exclusions="**/test_*.py,**/tests/**,**/*_test.py,**/test.py,**/Dockerfile*,**/docker-compose*.yml,**/.dockerignore,**/requirements.txt,**/healthcheck.sh,**/DEPLOYMENT.md,**/README.md,**/run.py,**/.venv/**,**/__pycache__/**" \
5454
-Dsonar.python.coverage.reportPaths=testing/coverage.xml \
5555
-Dsonar.python.xunit.reportPath=testing/test-results.xml \
56-
-Dsonar.coverage.exclusions="**/test_*.py,**/tests/**,**/*_test.py,**/test.py,**/__init__.py" \
56+
-Dsonar.coverage.exclusions="**/test_*.py,**/tests/**,**/*_test.py,**/test.py" \
5757
-Dsonar.sourceEncoding=UTF-8 \
5858
-Dsonar.python.version=3.13
5959

testing/run_tests.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,11 @@ export PROTOCOL="http"
3939
# add parent directory to python path for imports
4040
export PYTHONPATH="../:$PYTHONPATH"
4141

42-
# run all tests with combined coverage
42+
# run all tests with combined coverage (using .coveragerc configuration)
4343
echo "running all tests and generating combined coverage report..."
4444
pytest unit_tests/ integration_tests/ e2e_tests/ \
45-
--cov=../crypto_service \
46-
--cov=../pki_service \
47-
--cov=../common \
48-
--cov-report=xml:coverage.xml \
49-
--cov-report=html:htmlcov \
50-
--cov-report=term-missing \
51-
--cov-fail-under=50 \
52-
--junitxml=test-results.xml \
53-
-v
45+
--cov \
46+
--cov-fail-under=50
5447

5548
echo "tests completed successfully!"
5649
echo "coverage report generated: coverage.xml"

0 commit comments

Comments
 (0)