diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5ebef2c79..1dfefc8af 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -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 @@ -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: diff --git a/docs/contributing.rst b/docs/contributing.rst index aa1cba281..2d1f1b6e4 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -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 `_. diff --git a/scripts/test b/scripts/test index b9eca582b..521f5bdde 100755 --- a/scripts/test +++ b/scripts/test @@ -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