Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit bdea0e4

Browse files
authored
Fix: Improve coverage reporting in SonarCloud (#15)
* Fix: Restore accurate test coverage reporting in CI pipeline * Fix: Improve coverage reporting in SonarCloud * Address PR review feedback: add explanatory comments and fix CI_EXIT_ON_TEST_FAILURE handling
1 parent 915ec20 commit bdea0e4

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[run]
22
source = src.cli_code
3+
include =
4+
*/src/cli_code/*.py
5+
*/src/cli_code/*/*.py
6+
*/src/cli_code/*/*/*.py
37
omit =
48
*/.rules/*
59
*/.venv/*
@@ -10,6 +14,9 @@ omit =
1014
*/venv/*
1115
*/.pytest_cache/*
1216
*/site-packages/*
17+
# Excluded as it primarily contains integration code with external dependencies
18+
# that is difficult to test without mocking the entire Ollama API
19+
*/src/cli_code/models/ollama.py
1320

1421
[report]
1522
exclude_lines =

.github/workflows/python-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ jobs:
142142
-Dsonar.sourceEncoding=UTF-8
143143
-Dsonar.verbose=true
144144
-Dsonar.scm.provider=git
145+
-Dsonar.coverage.jacoco.xmlReportPaths=coverage.xml
146+
-Dsonar.newCode.referenceBranch=origin/main
145147
146148
# Add specific PR properties based on GitHub context
147149
- name: SonarCloud PR Analysis
@@ -158,6 +160,8 @@ jobs:
158160
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
159161
-Dsonar.pullrequest.branch=${{ github.head_ref }}
160162
-Dsonar.pullrequest.base=${{ github.base_ref }}
163+
-Dsonar.python.coverage.reportPaths=coverage.xml
164+
-Dsonar.coverage.jacoco.xmlReportPaths=coverage.xml
161165
162166
- name: Report SonarCloud Results
163167
run: |

scripts/run_coverage_ci.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ run_test_group "remaining" \
257257
echo "Generating final coverage report..." | tee -a "$SUMMARY_LOG"
258258
python -m pytest \
259259
--cov=src.cli_code \
260+
--cov-append \
260261
--cov-report=xml:coverage.xml \
261262
--cov-report=html:coverage_html \
262263
--cov-report=term
@@ -295,9 +296,8 @@ fi
295296

296297
echo "Coverage generation for CI completed." | tee -a "$SUMMARY_LOG"
297298

298-
# Determine exit code based on errors and CI environment
299-
# In CI we might want to exit gracefully for some failures
300-
CI_EXIT_ON_TEST_FAILURE=${CI_EXIT_ON_TEST_FAILURE:-1}
299+
# Use the CI_EXIT_ON_TEST_FAILURE value set at the beginning of the script (=1)
300+
# to determine whether to exit with an error code on test failures
301301

302302
if [ $FAILED_TESTS -gt 0 -o $TIMED_OUT_TESTS -gt 0 ]; then
303303
echo "Test run had $FAILED_TESTS failing tests and $TIMED_OUT_TESTS timed out tests" | tee -a "$SUMMARY_LOG"

sonar-project.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ sonar.tests=test_dir
1515
sonar.python.coverage.reportPaths=coverage.xml
1616

1717
# Configure test coverage exclusions
18+
# ollama.py is excluded as it primarily contains integration code with external dependencies
19+
# that is difficult to test without mocking the entire Ollama API
1820
sonar.coverage.exclusions=test_dir/**/*,tests/**/*,src/cli_code/models/ollama.py
1921

22+
# Force SonarCloud to see all files as new code to get proper coverage metrics
23+
# Note: We're using this temporarily to establish accurate baseline coverage
24+
# TODO: Remove this line after initial coverage baseline is established to ensure
25+
# future PRs are evaluated correctly for new code coverage
26+
sonar.newCode.referenceBranch=origin/main
27+
2028
# Specify Python version
2129
sonar.python.version=3.11
2230

0 commit comments

Comments
 (0)