Skip to content

Commit

Permalink
Fix Test Coverage Reporting (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
GunalKupta authored Jan 9, 2025
1 parent d51510e commit aebcb1f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 50 deletions.
54 changes: 25 additions & 29 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,6 @@ 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 @@ -192,7 +176,7 @@ blocks:
task:
agent:
machine:
type: s1-prod-ubuntu20-04-amd64-2
type: s1-prod-ubuntu20-04-amd64-3
env_vars:
- name: OS_NAME
value: linux
Expand All @@ -217,6 +201,18 @@ blocks:
- chmod u+r+x tools/source-package-verification.sh
- export TEST_CONSUMER_GROUP_PROTOCOL=consumer
- tools/source-package-verification.sh
- name: Build, Test, and Report coverage
commands:
- sem-version python 3.9
# use a virtualenv
- python3 -m venv _venv && source _venv/bin/activate
- chmod u+r+x tools/source-package-verification.sh
- export RUN_COVERAGE=true
- tools/source-package-verification.sh
- mkdir test-output
- cp test-report.xml test-output
- test-results publish test-output
- artifact push workflow coverage.xml
- name: "Source package verification with Python 3 (Linux arm64)"
dependencies: []
task:
Expand Down Expand Up @@ -302,15 +298,15 @@ blocks:
- 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
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
8 changes: 0 additions & 8 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,3 @@ Tox can be used to test against various supported Python versions (py27, py36, p
3. From top-level directory run:

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


### Running with test coverage
From top-level directory:
```
pip install tox
./tests/run.sh tox -e cover
```
12 changes: 12 additions & 0 deletions tools/source-package-verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ export LDFLAGS="$LDFLAGS -L${PWD}/${lib_dir}"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/$lib_dir"
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$PWD/$lib_dir"

if [[ $RUN_COVERAGE == true ]]; then
echo "Running tests with coverage"
# 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"
python3 -m pip install -e .
python -m pytest --cov confluent_kafka --cov-report term --cov-report html --cov-report xml \
--cov-branch --junitxml=test-report.xml tests/ --timeout 1200 --ignore=dest
exit 0
fi

python3 -m pip install .

if [[ $OS_NAME == linux && $ARCH == x64 ]]; then
Expand Down
16 changes: 3 additions & 13 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,16 +20,6 @@ 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 aebcb1f

Please sign in to comment.