Skip to content

Commit 7a6da86

Browse files
avidaDmytro Rezchykov
and
Dmytro Rezchykov
authored
add coverage report (#6045)
Co-authored-by: Dmytro Rezchykov <[email protected]>
1 parent 0691e77 commit 7a6da86

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

.github/workflows/test-command.yml

+11
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ jobs:
195195
**/normalization_test_output/**/build/compiled/airbyte_utils/**
196196
**/normalization_test_output/**/build/run/airbyte_utils/**
197197
**/normalization_test_output/**/models/generated/**
198+
199+
- name: Test coverage reports artifacts
200+
if: github.event.inputs.comment-id && success()
201+
uses: actions/upload-artifact@v2
202+
with:
203+
name: test-reports
204+
path: |
205+
**/${{ github.event.inputs.connector }}/htmlcov/**
206+
retention-days: 3
207+
198208
- name: Report Status
199209
if: github.ref == 'refs/heads/master' && always()
200210
run: ./tools/status/report.sh ${{ github.event.inputs.connector }} ${{github.repository}} ${{github.run_id}} ${{steps.test.outcome}}
@@ -209,6 +219,7 @@ jobs:
209219
comment-id: ${{ github.event.inputs.comment-id }}
210220
body: |
211221
> :white_check_mark: ${{github.event.inputs.connector}} https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
222+
${{env.PYTHON_UNITTEST_COVERAGE_REPORT}}
212223
- name: Add Failure Comment
213224
if: github.event.inputs.comment-id && failure()
214225
uses: peter-evans/create-or-update-comment@v1

buildSrc/src/main/groovy/airbyte-python.gradle

+9-8
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ class AirbytePythonConfiguration {
1313
class Helpers {
1414
static addTestTaskIfTestFilesFound(Project project, String testFilesDirectory, String taskName, taskDependencies) {
1515
"""
16-
This method verifies if there are test files in a directory before adding the pytest task to run tests on that directory. This is needed
16+
This method verifies if there are test files in a directory before adding the pytest task to run tests on that directory. This is needed
1717
because if there are no tests in that dir and we run pytest on it, it exits with exit code 5 which gradle takes to mean that the process
1818
failed, since it's non-zero. This means that if a module doesn't need a unit or integration test, it still needs to add a dummy test file
19-
like:
20-
19+
like:
20+
2121
```
2222
def make_ci_pass_test():
2323
assert True
2424
```
25-
25+
2626
So we use this method to leverage pytest's test discovery rules (https://docs.pytest.org/en/6.2.x/goodpractices.html#conventions-for-python-test-discovery)
27-
to selectively run pytest based on whether there seem to be test files in that directory.
28-
Namely, if the directory contains a file whose name is test_*.py or *_test.py then it's a test.
29-
27+
to selectively run pytest based on whether there seem to be test files in that directory.
28+
Namely, if the directory contains a file whose name is test_*.py or *_test.py then it's a test.
29+
3030
See https://github.com/airbytehq/airbyte/issues/4979 for original context
3131
"""
3232
if (project.file(testFilesDirectory).exists()) {
3333

3434
project.projectDir.toPath().resolve(testFilesDirectory).traverse(type: FileType.FILES, nameFilter: ~/(^test_.*|.*_test)\.py$/) { file ->
3535
project.task(taskName, type: PythonTask, dependsOn: taskDependencies) {
3636
module = "pytest"
37-
command = "-s ${testFilesDirectory}"
37+
command = "-s ${testFilesDirectory} --cov=./ --cov-config=${project.rootProject.file('tools/python/.coveragerc').absolutePath} --cov-report html --cov-report term"
3838
}
3939
// If a file is found, terminate the traversal, thus causing this task to be declared at most once
4040
return FileVisitResult.TERMINATE
@@ -68,6 +68,7 @@ class AirbytePythonPlugin implements Plugin<Project> {
6868
pip 'mypy:0.812'
6969
pip 'isort:5.6.4'
7070
pip 'pytest:6.1.2'
71+
pip 'pytest-cov:2.12.1'
7172
pip 'pip:21.1.3'
7273
}
7374

tools/bin/ci_integration_test.sh

+20-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,27 @@ run | tee build.out
4646
# return status of "run" command, not "tee"
4747
# https://tldp.org/LDP/abs/html/internalvariables.html#PIPESTATUSREF
4848
run_status=${PIPESTATUS[0]}
49+
4950
test $run_status == "0" || {
51+
# Build failed
52+
link=$(cat build.out | grep -A1 "Publishing build scan..." | tail -n1 | tr -d "\n")
5053
# Save gradle scan link to github GRADLE_SCAN_LINK variable for next job.
5154
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
52-
LINK=$(cat build.out | grep -A1 "Publishing build scan..." | tail -n1 | tr -d "\n")
53-
echo "GRADLE_SCAN_LINK=$LINK" >> $GITHUB_ENV
55+
echo "GRADLE_SCAN_LINK=$link" >> $GITHUB_ENV
56+
exit $run_status
5457
}
55-
exit $run_status
58+
59+
# Build successed
60+
coverage_report=`sed -n '/^[ \t]*-\+ coverage: /,/TOTAL /p' build.out`
61+
62+
if ! test -z "$coverage_report"
63+
then
64+
echo "PYTHON_UNITTEST_COVERAGE_REPORT<<EOF" >> $GITHUB_ENV
65+
echo "Python tests coverage:" >> $GITHUB_ENV
66+
echo '```' >> $GITHUB_ENV
67+
echo "$coverage_report" >> $GITHUB_ENV
68+
echo '```' >> $GITHUB_ENV
69+
echo "EOF" >> $GITHUB_ENV
70+
else
71+
echo "PYTHON_UNITTEST_COVERAGE_REPORT=No Python unittests run" >> $GITHUB_ENV
72+
fi

tools/python/.coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
omit =
3+
.venv/*
4+
main.py
5+
setup.py
6+
unit_tests/*
7+
integration_tests/*

0 commit comments

Comments
 (0)