coverage-check.sh 762 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # Run tests with coverage and fail if below threshold
  3. # Usage: ./coverage-check.sh [--threshold 80] [pytest-args...]
  4. set -e
  5. THRESHOLD=80
  6. PYTEST_ARGS=""
  7. # Parse arguments
  8. while [[ $# -gt 0 ]]; do
  9. case $1 in
  10. --threshold)
  11. THRESHOLD="$2"
  12. shift 2
  13. ;;
  14. *)
  15. PYTEST_ARGS="$PYTEST_ARGS $1"
  16. shift
  17. ;;
  18. esac
  19. done
  20. echo "=== Running tests with coverage ==="
  21. echo "Minimum coverage threshold: ${THRESHOLD}%"
  22. echo ""
  23. # Run pytest with coverage
  24. pytest \
  25. --cov=src \
  26. --cov-report=term-missing \
  27. --cov-report=html \
  28. --cov-fail-under=${THRESHOLD} \
  29. ${PYTEST_ARGS}
  30. echo ""
  31. echo "=== Coverage report generated ==="
  32. echo "HTML report: htmlcov/index.html"