Skip to content

Run test script with/without coverage #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ jobs:
pip install -e ".[validation]"

- name: Execute test suite
# --fail-under=0 ensures we publish the coverage regardless of whether it meets
# the minimum so we can use Codecov to evaluate gaps
run: |
coverage run --source=pystac/ -m unittest discover tests/
coverage xml --fail-under=0
run: ./scripts/test
env:
CHECK_COVERAGE: true

- name: Prepare ./coverage.xml
# Ignore the configured fail-under to ensure we upload the coverage report. We
# will trigger a failure for coverage drops in a later job
run: coverage xml --fail-under 0

- name: Upload All coverage to Codecov
uses: codecov/codecov-action@v1
Expand All @@ -111,6 +114,11 @@ jobs:
file: ./coverage.xml
fail_ci_if_error: false

- name: Check for coverage drop
# This will use the configured fail-under, causing this job to fail if the
# coverage drops.
run: coverage report

lint:
runs-on: ubuntu-latest
strategy:
Expand Down
4 changes: 4 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ or the entire project using:

./scripts/test

The last command will also check test coverage. To view the coverage report, you can run
`coverage report` (to view the report in the terminal) or `coverage html` (to generate
an HTML report that can be opened in a browser).

More details on using ``unittest`` are `here
<https://docs.python.org/3/library/unittest.html>`_.

Expand Down
16 changes: 10 additions & 6 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ set -e
if [[ -z ${CI} ]]; then
pre-commit run --all-files
fi

echo
echo " -- RUNNING UNIT TESTS --"
echo

# Test suite with coverage enabled
coverage run -m unittest discover tests
coverage xml
if [[ -z ${CI} || -n ${CHECK_COVERAGE} ]]; then
echo " -- RUNNING UNIT TESTS (WITH COVERAGE) --"
# Test suite with coverage enabled
coverage run -m unittest discover tests
else
echo " -- RUNNING UNIT TESTS (WITHOUT COVERAGE) --"
python -m unittest discover tests
fi

echo