From 668d3e784dd75b965df77205748090005b1e5c50 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:45:03 -0500 Subject: [PATCH] Changed testing workflow to check coverage (#259) --- .github/workflows/python-test.yaml | 38 +++++++++++++----------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-test.yaml b/.github/workflows/python-test.yaml index a6d6c78..bfeef4f 100644 --- a/.github/workflows/python-test.yaml +++ b/.github/workflows/python-test.yaml @@ -5,11 +5,7 @@ on: types: [opened, reopened, synchronize] branches: [dev] paths: - - "src/ecooptimizer/analyzers/**/*.py" - - "src/ecooptimizer/measurements/**/*.py" - - "src/ecooptimizer/refactorers/**/*.py" - - "src/ecooptimizer/utils/**/*.py" - - "src/ecooptimizer/testing/**/*.py" + - "src/ecooptimizer/**/*.py" jobs: test: @@ -41,25 +37,25 @@ jobs: pip install . pip install .'[dev]' - - name: Get changed modules - id: changed-modules + - name: Get changed files + id: changed-files uses: tj-actions/changed-files@v45 with: files: | - src/ecooptimizer/analyzers/**/*.py - src/ecooptimizer/measurements/**/*.py - src/ecooptimizer/refactorers/**/*.py - src/ecooptimizer/utils/**/*.py - src/ecooptimizer/testing/**/*.py - dir_names: True + src/ecooptimizer/**/*.py - - name: Run Pytest - if: steps.changed-modules.outputs.any_changed == 'true' - env: - ALL_CHANGED_MODULES: ${{ steps.changed-modules.outputs.all_changed_files }} + - name: Run Tests and Generate Coverage Report run: | - for module in ${ALL_CHANGED_MODULES}; do - folder="$(basename $module)" - pytest "tests/$folder/" + pytest --cov=src/ecooptimizer --cov-branch --cov-report=xml --cov-report=term-missing + + - name: Check Coverage for Changed Lines + run: | + git fetch origin ${{ github.base_ref }} + diff-cover coverage.xml --compare-branch=origin/${{ github.base_ref }} --fail-under=80 + + - name: Check Per-File Coverage + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "Checking overall coverage for $file" + coverage report --include=$file --fail-under=80 || exit 1 done -