Skip to content

feat: Add pytest coverage comment to PRs #1063

feat: Add pytest coverage comment to PRs

feat: Add pytest coverage comment to PRs #1063

Workflow file for this run

name: Test Workflow with Coverage
on:
push:
branches:
- main
- dev
- hotfix
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
branches:
- main
- dev
- hotfix
permissions:
contents: read
actions: read
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- 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 tests with coverage
if: env.skip_tests == 'false'
run: |
pytest --cov=src/backend --cov-report=term-missing --cov-report=xml --junitxml=pytest.xml --ignore=tests/e2e-test/tests --omit="*/tests/*"
- name: Pytest Coverage Comment
if: |
always() &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
env.skip_tests == 'false'
uses: MishaKav/pytest-coverage-comment@26f986d2599c288bb62f623d29c2da98609e9cd4 # v1.6.0
with:
pytest-xml-coverage-path: coverage.xml
junitxml-path: pytest.xml
report-only-changed-files: true
- name: Skip coverage report if no tests
if: env.skip_tests == 'true'
run: |
echo "Skipping coverage report because no tests were found."