Merge pull request #31 from TCS-2021/final-app #106
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: tests.yml | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set up Python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pytest pytest-cov | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| # Install the package in development mode if it has a setup.py | |
| if [ -f setup.py ]; then pip install -e .; fi | |
| - name: Run pytest | |
| run: | | |
| pytest --cov=./ --cov-report=xml --cov-report=term-missing -v | |
| - name: Generate test summary | |
| if: always() | |
| run: | | |
| echo "### Pytest Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ -f .coverage ]; then | |
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; root = ET.parse('coverage.xml').getroot(); print(root.get('line-rate'))") | |
| COVERAGE_PCT=$(python -c "print(round(float('${COVERAGE}') * 100, 2))") | |
| echo "📊 **Code Coverage**: ${COVERAGE_PCT}%" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # Get test results summary | |
| PASSED=$(pytest --collect-only | grep -o '[0-9]* passed' | awk '{print $1}' || echo "0") | |
| FAILED=$(pytest --collect-only | grep -o '[0-9]* failed' | awk '{print $1}' || echo "0") | |
| SKIPPED=$(pytest --collect-only | grep -o '[0-9]* skipped' | awk '{print $1}' || echo "0") | |
| TOTAL=$((PASSED + FAILED + SKIPPED)) | |
| echo "**Test Results**:" >> $GITHUB_STEP_SUMMARY | |
| echo "- Total Tests: ${TOTAL}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Passed: ${PASSED}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Failed: ${FAILED}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Skipped: ${SKIPPED}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "For detailed test results, check the job logs or download the artifacts." >> $GITHUB_STEP_SUMMARY | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pytest-results | |
| path: | | |
| coverage.xml | |
| .coverage | |
| - name: Check test failures | |
| run: | | |
| # Exit with error if tests failed | |
| pytest --quiet || exit 1 |