Skip to content

Commit aebcb1f

Browse files
authored
Fix Test Coverage Reporting (#1892)
1 parent d51510e commit aebcb1f

File tree

4 files changed

+40
-50
lines changed

4 files changed

+40
-50
lines changed

.semaphore/semaphore.yml

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@ global_job_config:
1414
- checkout
1515
- mkdir artifacts
1616
blocks:
17-
# - name: Test
18-
# dependencies: []
19-
# run:
20-
# # don't run the tests on non-functional changes...
21-
# when: "change_in('/', {exclude: ['.github/']})"
22-
# task:
23-
# jobs:
24-
# - name: Test
25-
# commands:
26-
# - sem-version python 3.9
27-
# - pip install tox
28-
# - tox -e cover
29-
# - mkdir test-output
30-
# - cp test-report.xml test-output
31-
# - test-results publish test-output
32-
# - artifact push workflow coverage.xml
3317
- name: "Wheels: OSX x64 - Python 3.6-3.12"
3418
run:
3519
when: "tag =~ '.*'"
@@ -192,7 +176,7 @@ blocks:
192176
task:
193177
agent:
194178
machine:
195-
type: s1-prod-ubuntu20-04-amd64-2
179+
type: s1-prod-ubuntu20-04-amd64-3
196180
env_vars:
197181
- name: OS_NAME
198182
value: linux
@@ -217,6 +201,18 @@ blocks:
217201
- chmod u+r+x tools/source-package-verification.sh
218202
- export TEST_CONSUMER_GROUP_PROTOCOL=consumer
219203
- tools/source-package-verification.sh
204+
- name: Build, Test, and Report coverage
205+
commands:
206+
- sem-version python 3.9
207+
# use a virtualenv
208+
- python3 -m venv _venv && source _venv/bin/activate
209+
- chmod u+r+x tools/source-package-verification.sh
210+
- export RUN_COVERAGE=true
211+
- tools/source-package-verification.sh
212+
- mkdir test-output
213+
- cp test-report.xml test-output
214+
- test-results publish test-output
215+
- artifact push workflow coverage.xml
220216
- name: "Source package verification with Python 3 (Linux arm64)"
221217
dependencies: []
222218
task:
@@ -302,15 +298,15 @@ blocks:
302298
- 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
303299
- echo Thank you
304300

305-
# after_pipeline:
306-
# task:
307-
# agent:
308-
# machine:
309-
# type: s1-prod-ubuntu20-04-amd64-1
310-
# jobs:
311-
# - name: SonarQube
312-
# commands:
313-
# - checkout
314-
# - sem-version java 11
315-
# - artifact pull workflow coverage.xml
316-
# - emit-sonarqube-data --run_only_sonar_scan
301+
after_pipeline:
302+
task:
303+
agent:
304+
machine:
305+
type: s1-prod-ubuntu20-04-amd64-1
306+
jobs:
307+
- name: SonarQube
308+
commands:
309+
- checkout
310+
- sem-version java 11
311+
- artifact pull workflow coverage.xml
312+
- emit-sonarqube-data --run_only_sonar_scan

tests/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,3 @@ Tox can be used to test against various supported Python versions (py27, py36, p
122122
3. From top-level directory run:
123123

124124
```$ ./tests/run.sh tox```
125-
126-
127-
### Running with test coverage
128-
From top-level directory:
129-
```
130-
pip install tox
131-
./tests/run.sh tox -e cover
132-
```

tools/source-package-verification.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ export LDFLAGS="$LDFLAGS -L${PWD}/${lib_dir}"
1515
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/$lib_dir"
1616
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$PWD/$lib_dir"
1717

18+
if [[ $RUN_COVERAGE == true ]]; then
19+
echo "Running tests with coverage"
20+
# Install source with editable flag (-e) so that SonarQube can parse the coverage report.
21+
# Otherwise, the report shows source files located in site-packages, which SonarQube cannot find.
22+
# Example: ".tox/cover/lib/python3.11/site-packages/confluent_kafka/__init__.py"
23+
# instead of "src/confluent_kafka/__init__.py"
24+
python3 -m pip install -e .
25+
python -m pytest --cov confluent_kafka --cov-report term --cov-report html --cov-report xml \
26+
--cov-branch --junitxml=test-report.xml tests/ --timeout 1200 --ignore=dest
27+
exit 0
28+
fi
29+
1830
python3 -m pip install .
1931

2032
if [[ $OS_NAME == linux && $ARCH == x64 ]]; then

tox.ini

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
envlist = flake8,py37,py38,py39,py310,py311,py312,py313
33

44
[testenv]
5-
deps =
6-
-r requirements/requirements-tests-install.txt
7-
.
85
passenv =
96
#http://tox.readthedocs.io/en/latest/config.html#confval-passenv=SPACE-SEPARATED-GLOBNAMES
107
*
118
commands =
9+
# Install main package and all sub-packages
10+
pip install -r requirements/requirements-tests-install.txt
11+
pip install .
1212
# Early verification that module is loadable
1313
python -c 'import confluent_kafka ; print(confluent_kafka.version())'
1414
# Run tests (large timeout to allow docker image downloads)
@@ -20,16 +20,6 @@ commands =
2020
deps = flake8
2121
commands = flake8
2222

23-
[testenv:cover]
24-
commands =
25-
# Install source with editable flag (-e) so that SonarQube can parse the coverage report.
26-
# Otherwise, the report shows source files located in site-packages, which SonarQube cannot find.
27-
# Example: ".tox/cover/lib/python3.11/site-packages/confluent_kafka/__init__.py"
28-
# instead of "src/confluent_kafka/__init__.py"
29-
pip install -e .
30-
pytest {env:PYTESTARGS:} --cov confluent_kafka --cov-report term --cov-report html --cov-report xml \
31-
--cov-branch --junitxml=test-report.xml tests/ {posargs}
32-
3323
[pytest]
3424
python_files = test_*
3525
testpaths = tests

0 commit comments

Comments
 (0)