Refactor backend test execution to streamline coverage reporting and … #859
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Workflow with Coverage | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| - demo | |
| - hotfix | |
| - dev-v4 | |
| - macae-v4-unittestcases-kd | |
| pull_request: | |
| types: | |
| - opened | |
| - ready_for_review | |
| - reopened | |
| - synchronize | |
| branches: | |
| - main | |
| - dev | |
| - demo | |
| - hotfix | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r src/backend/requirements.txt | |
| - name: Check if test files exist | |
| id: check_tests | |
| run: | | |
| if [ -z "$(find src -type f -name 'test_*.py')" ]; then | |
| echo "No test files found, skipping tests." | |
| echo "skip_tests=true" >> $GITHUB_ENV | |
| else | |
| echo "Test files found, running tests." | |
| echo "skip_tests=false" >> $GITHUB_ENV | |
| fi | |
| - name: Run backend tests with coverage | |
| if: env.skip_tests == 'false' | |
| run: | | |
| python -m pytest src/tests/backend/test_app.py --cov=backend.app --cov-report= --cov-config=.coveragerc -q > /dev/null 2>&1 | |
| python -m pytest src/tests/backend --cov=backend --cov-append --cov-report= --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py | |
| python -m coverage report --rcfile=.coveragerc | |
| - name: Skip coverage report if no tests | |
| if: env.skip_tests == 'true' | |
| run: | | |
| echo "Skipping coverage report because no tests were found." |