Skip to content

Workflow file for this run

# This is a basic workflow to run automated test-cases on GitHub App Action
name: Running Python Unit Tests for Splunk-App-Action
# Controls when the action will run. Triggers the workflow on push or pull request
on:
push:
branches:
- 'develop'
pull_request:
branches:
- '*'
- '*/*'
- '**'
workflow_dispatch:
jobs:
python-unit-tests:
name: "Running Python Unit Test Cases"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
- name: Run Python Unit Tests
run: pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=src --cov-config=tests/.coveragerc --cov-report=xml
- name: Linting with Ruff
run: ruff --output-format=github .
continue-on-error: true # need to remove this later on to catch the errors anf fail the workflow on linting errors
- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: pytest-results
path: junit/test-results.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Write Pytest Results to Job Summary
if: always()
uses: pmeier/pytest-results-action@main
with:
path: junit/test-results.xml
# (Optional) Add a summary of the results at the top of the report
summary: true
# (Optional) Select which results should be included in the report.
# Follows the same syntax as `pytest -r`
display-options: fEX
# (Optional) Fail the workflow if no JUnit XML was found.
fail-on-empty: true
# (Optional) Title of the test results section in the workflow summary
title: Pytest Results
- name: Pytest Coverage Comment
id: pytest_coverage
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-xml-coverage-path: ./coverage.xml
junitxml-path: ./unit/test-results.xml
title: Pytest Coverage
- name: Write Pytest Coverage Report to Job Summary
run: |
echo "# Pytest Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "[![Coverage](https://img.shields.io/badge/coverage-${{ steps.pytest_coverage.outputs.coverage }}%25-red)](example_coverage_report_url)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Tests:** ${{ steps.pytest_coverage.outputs.tests }}" >> $GITHUB_STEP_SUMMARY
echo "- **Skipped:** ${{ steps.pytest_coverage.outputs.skipped }}" >> $GITHUB_STEP_SUMMARY
echo "- **Failures:** ${{ steps.pytest_coverage.outputs.failures }}" >> $GITHUB_STEP_SUMMARY
echo "- **Errors:** ${{ steps.pytest_coverage.outputs.errors }}" >> $GITHUB_STEP_SUMMARY
echo "- **Time:** ${{ steps.pytest_coverage.outputs.time }} seconds" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Detailed Report" >> $GITHUB_STEP_SUMMARY
echo "- **Coverage:** ${{ steps.pytest_coverage.outputs.coverage }}%" >> $GITHUB_STEP_SUMMARY
echo "- **Color:** Red" >> $GITHUB_STEP_SUMMARY
echo "- **Warnings:** ${{ steps.pytest_coverage.outputs.warnings }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Test Details" >> $GITHUB_STEP_SUMMARY
echo "- **Not Successful Test Info:** ${{ steps.pytest_coverage.outputs.notSuccessTestInfo }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "*Note: Replace 'example_coverage_report_url' with the actual URL where your coverage report is hosted.*" >> $GITHUB_STEP_SUMMARY