Skip to content

Commit 08a1cc1

Browse files
Adds code coverage recommendations in GitHub workflow. (Netflix#4489)
* Prepares Github workflow for future code coverage requirements. * Omits coverage for specified files. Adds coverage details to log message. * Fixes GitHub workflow variable references. * Moves variable assignment to appropriate scope. * Fixes code coverage check per file. * Ignores code coverage for specified files. * Adds percentage symbol to code coverage message. * Improves text alignment for code coverage log messages. * Improves text alignment for code coverage log messages. * Improves text alignment for code coverage log messages. * Fixes formatting. * Fixes formatting.
1 parent da99f59 commit 08a1cc1

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

.coveragerc

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[run]
2+
omit =
3+
*/__init__.py
4+
*/views.py
5+
*/scheduled.py
6+
src/dispatch/rate_limiter.py
7+
src/dispatch/plugins/dispatch_test/*
8+
src/dispatch/api.py
9+
src/dispatch/extensions.py
10+
src/dispatch/scheduler.py
11+
12+
[report]
13+
omit =
14+
*/__init__.py
15+
*/views.py
16+
*/scheduled.py
17+
src/dispatch/rate_limiter.py
18+
src/dispatch/plugins/dispatch_test/*
19+
src/dispatch/api.py
20+
src/dispatch/extensions.py
21+
src/dispatch/scheduler.py
22+

.github/workflows/python.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ on: pull_request
44

55
jobs:
66
test:
7+
env:
8+
# Minimum code coverage per file
9+
COVERAGE_SINGLE: 50
10+
# Minimum total code coverage
11+
COVERAGE_TOTAL: 70
712
runs-on: ubuntu-latest
813
services:
914
postgres:
@@ -41,4 +46,21 @@ jobs:
4146
- name: Test with pytest
4247
run: |
4348
pip install pytest-cov
44-
pytest --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
49+
pytest --junitxml=junit/test-results.xml --cov=dispatch --cov-report=json:coverage.json --cov-report=xml --cov-report=html
50+
- name: Coverage per file
51+
# TODO: Change this recommendation into a requirement.
52+
run: |
53+
export FAILED_COVERAGE_PER_FILE=$(python -c "import json;files=json.load(open('coverage.json'))['files'];covs=map(lambda k, v: (k, v['summary']['percent_covered_display']),files.keys(),files.values()); f=filter(lambda cov:int(cov[1])<${{ env.COVERAGE_SINGLE }},covs); print('\n'.join('{:<68}{:>3}%'.format(k,v) for k,v in f))")
54+
if [[ $FAILED_COVERAGE_PER_FILE != "" ]]; then
55+
echo "FAIL Recommended file(s) test coverage of ${{ env.COVERAGE_SINGLE }}% not reached."
56+
echo -e "Failed file coverage(s):\n$FAILED_COVERAGE_PER_FILE"
57+
# exit 1
58+
fi
59+
- name: Coverage total
60+
# TODO: Change this recommendation into a requirement.
61+
run: |
62+
export COVERAGE_TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
63+
if [[ $COVERAGE_TOTAL < ${{ env.COVERAGE_TOTAL }} ]]; then
64+
echo "FAIL Recommended total test coverage of ${{ env.COVERAGE_TOTAL }}% not reached. Total coverage: $COVERAGE_TOTAL%"
65+
# exit 1
66+
fi

0 commit comments

Comments
 (0)