Skip to content

Commit

Permalink
DGS-16859: Enable SonarQube code coverage reporting (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
GunalKupta authored Jan 6, 2025
1 parent 1cf37de commit e91dc57
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ tmp-KafkaCluster
venv_test
venv_examples
*Zone.Identifier
.coverage
**/coverage.xml
**/test-report.xml
29 changes: 29 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ global_job_config:
- checkout
- mkdir artifacts
blocks:
- name: Test
dependencies: []
run:
# don't run the tests on non-functional changes...
when: "change_in('/', {exclude: ['.github/']})"
task:
jobs:
- name: Test
commands:
- sem-version python 3.9
- pip install tox
- tox -e cover
- mkdir test-output
- cp test-report.xml test-output
- test-results publish test-output
- artifact push workflow coverage.xml
- name: "Wheels: OSX x64 - Python 3.6-3.12"
run:
when: "tag =~ '.*'"
Expand Down Expand Up @@ -285,3 +301,16 @@ blocks:
- cd ..
- artifact push project artifacts/confluent-kafka-python-wheels-${SEMAPHORE_GIT_TAG_NAME}-${SEMAPHORE_WORKFLOW_ID}.tgz --destination confluent-kafka-python-wheels-${SEMAPHORE_GIT_TAG_NAME}-${SEMAPHORE_WORKFLOW_ID}.tgz
- echo Thank you

after_pipeline:
task:
agent:
machine:
type: s1-prod-ubuntu20-04-amd64-1
jobs:
- name: SonarQube
commands:
- checkout
- sem-version java 11
- artifact pull workflow coverage.xml
- emit-sonarqube-data --run_only_sonar_scan
1 change: 1 addition & 0 deletions requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pytest
pytest-timeout
requests-mock
respx
pytest_cov
6 changes: 6 additions & 0 deletions service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ git:
github:
enable: true
repo_name: confluentinc/confluent-kafka-python
sonarqube:
enable: true
coverage_exclusions:
- "**/*.pb.*"
- "**/mk-include/**/*"
- "examples/**"
semaphore:
enable: true
pipeline_enable: false
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### service-bot sonarqube plugin managed file
sonar.coverage.exclusions=**/test/**/*,**/tests/**/*,**/mock/**/*,**/mocks/**/*,**/*mock*,**/*test*
sonar.cpd.exclusions=**/test/**/*,**/tests/**/*,**/mock/**/*,**/mocks/**/*,**/*mock*,**/*test*
sonar.exclusions=**/*.pb.*,**/mk-include/**/*
sonar.exclusions=**/*.pb.*,**/mk-include/**/*,examples/**
sonar.language=python
sonar.projectKey=confluent-kafka-python
sonar.python.coverage.reportPaths=**/coverage.xml
Expand Down
7 changes: 7 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ Tox can be used to test against various supported Python versions (py27, py36, p

```$ ./tests/run.sh tox```


### Running with test coverage
From top-level directory:
```
pip install tox
./tests/run.sh tox -e cover
```
16 changes: 13 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
envlist = flake8,py37,py38,py39,py310,py311,py312,py313

[testenv]
deps =
-r requirements/requirements-tests-install.txt
.
passenv =
#http://tox.readthedocs.io/en/latest/config.html#confval-passenv=SPACE-SEPARATED-GLOBNAMES
*
commands =
# Install main package and all sub-packages
pip install -r requirements/requirements-tests-install.txt
pip install .
# Early verification that module is loadable
python -c 'import confluent_kafka ; print(confluent_kafka.version())'
# Run tests (large timeout to allow docker image downloads)
Expand All @@ -20,6 +20,16 @@ commands =
deps = flake8
commands = flake8

[testenv:cover]
commands =
# Install source with editable flag (-e) so that SonarQube can parse the coverage report.
# Otherwise, the report shows source files located in site-packages, which SonarQube cannot find.
# Example: ".tox/cover/lib/python3.11/site-packages/confluent_kafka/__init__.py"
# instead of "src/confluent_kafka/__init__.py"
pip install -e .
pytest {env:PYTESTARGS:} --cov confluent_kafka --cov-report term --cov-report html --cov-report xml \
--cov-branch --junitxml=test-report.xml tests/ {posargs}

[pytest]
python_files = test_*
testpaths = tests
Expand Down

0 comments on commit e91dc57

Please sign in to comment.