Skip to content

Commit 1415f95

Browse files
author
Jon Duckworth
authored
Merge pull request #486 from duckontheweb/change/coverage-ci
Run test script with/without coverage
2 parents 93d7720 + 42144a6 commit 1415f95

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,14 @@ jobs:
111111
pip install -e ".[validation]"
112112
113113
- name: Execute test suite
114-
# --fail-under=0 ensures we publish the coverage regardless of whether it meets
115-
# the minimum so we can use Codecov to evaluate gaps
116-
run: |
117-
coverage run --source=pystac/ -m unittest discover tests/
118-
coverage xml --fail-under=0
114+
run: ./scripts/test
115+
env:
116+
CHECK_COVERAGE: true
117+
118+
- name: Prepare ./coverage.xml
119+
# Ignore the configured fail-under to ensure we upload the coverage report. We
120+
# will trigger a failure for coverage drops in a later job
121+
run: coverage xml --fail-under 0
119122

120123
- name: Upload All coverage to Codecov
121124
uses: codecov/codecov-action@v1
@@ -125,6 +128,11 @@ jobs:
125128
file: ./coverage.xml
126129
fail_ci_if_error: false
127130

131+
- name: Check for coverage drop
132+
# This will use the configured fail-under, causing this job to fail if the
133+
# coverage drops.
134+
run: coverage report
135+
128136
lint:
129137
runs-on: ubuntu-latest
130138
strategy:

docs/contributing.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ or the entire project using:
3939
4040
./scripts/test
4141
42+
The last command will also check test coverage. To view the coverage report, you can run
43+
`coverage report` (to view the report in the terminal) or `coverage html` (to generate
44+
an HTML report that can be opened in a browser).
45+
4246
More details on using ``unittest`` are `here
4347
<https://docs.python.org/3/library/unittest.html>`_.
4448

scripts/test

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ set -e
55
if [[ -z ${CI} ]]; then
66
pre-commit run --all-files
77
fi
8-
9-
echo
10-
echo " -- RUNNING UNIT TESTS --"
118
echo
129

13-
# Test suite with coverage enabled
14-
coverage run -m unittest discover tests
15-
coverage xml
10+
if [[ -z ${CI} || -n ${CHECK_COVERAGE} ]]; then
11+
echo " -- RUNNING UNIT TESTS (WITH COVERAGE) --"
12+
# Test suite with coverage enabled
13+
coverage run -m unittest discover tests
14+
else
15+
echo " -- RUNNING UNIT TESTS (WITHOUT COVERAGE) --"
16+
python -m unittest discover tests
17+
fi
18+
19+
echo

0 commit comments

Comments
 (0)