Files
TimeTracker/scripts/run-tests.sh
T
Dries Peeters 768b0b5b6d fix(ci): harden security pytest lane and Safety report output
Security pytest:
- Run an explicit node list instead of -m security over the whole tests
  tree, so collection stays small and nothing is spuriously deselected.
- Use a writable pytest cache under INSTALLATION_CONFIG_DIR and filter
  the known Flask-SQLAlchemy SAWarning on metadata DROP ordering.
- Add scripts/ci/security-pytest.sh and wire Makefile, run-tests.sh/.bat,
  and ci-comprehensive to call it for a single source of truth.

Safety:
- Write JSON to .test_installation_config/safety-report.json (with the
  rest of local CI artifacts) instead of the repo root.
- Run scripts/ci/sanitize_safety_report.py after each scan so paths in
  the report are workspace-relative for artifacts and reviews.
- Capture Safety exit codes so failures still print where the report was
  written; use python -m safety in workflows where appropriate.

Release and legacy workflows pick up the new report path, sanitizer,
and a pinned Safety install where the CLI is invoked.
2026-05-13 12:46:35 +02:00

98 lines
3.0 KiB
Bash

#!/bin/bash
# TimeTracker Test Runner for Linux/Mac
# Quick test execution script
set -e
echo "========================================"
echo "TimeTracker Test Runner"
echo "========================================"
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if pytest is installed
if ! python -m pytest --version > /dev/null 2>&1; then
echo -e "${RED}ERROR: pytest not found!${NC}"
echo "Please install test dependencies:"
echo " pip install -r requirements-test.txt"
exit 1
fi
# Parse command line arguments
case "$1" in
smoke)
echo -e "${GREEN}Running smoke tests (quick critical tests)...${NC}"
python -m pytest -m smoke -v
;;
unit)
echo -e "${GREEN}Running unit tests...${NC}"
python -m pytest -m unit -v
;;
integration)
echo -e "${GREEN}Running integration tests...${NC}"
python -m pytest -m integration -v
;;
security)
echo -e "${GREEN}Running security tests...${NC}"
bash scripts/ci/security-pytest.sh
;;
database)
echo -e "${GREEN}Running database tests...${NC}"
python -m pytest -m database -v
;;
all)
echo -e "${GREEN}Running full test suite in parallel...${NC}"
python -m pytest -v -n auto
;;
coverage)
echo -e "${GREEN}Running tests with coverage...${NC}"
python -m pytest --cov=app --cov-report=html --cov-report=term-missing
echo ""
echo -e "${GREEN}Coverage report generated in htmlcov/index.html${NC}"
;;
fast)
echo -e "${GREEN}Running tests in parallel (fast mode)...${NC}"
python -m pytest -n auto -v
;;
parallel)
echo -e "${GREEN}Running tests in parallel with 4 workers...${NC}"
python -m pytest -n 4 -v
;;
watch)
echo -e "${GREEN}Running tests in watch mode...${NC}"
python -m pytest-watch
;;
failed)
echo -e "${GREEN}Re-running last failed tests...${NC}"
python -m pytest --lf -v
;;
*)
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " smoke - Run smoke tests (fastest, < 1 min)"
echo " unit - Run unit tests (2-5 min)"
echo " integration - Run integration tests (5-10 min)"
echo " security - Run security tests (3-5 min)"
echo " database - Run database tests (5-10 min)"
echo " all - Run full test suite (15-30 min)"
echo " coverage - Run tests with coverage report"
echo " fast - Run tests in parallel (auto workers)"
echo " parallel - Run tests in parallel (4 workers)"
echo " watch - Run tests in watch mode (pytest-watch)"
echo " failed - Re-run last failed tests"
echo ""
echo "Examples:"
echo " $0 smoke"
echo " $0 coverage"
echo " $0 fast"
exit 1
;;
esac