Add setup-test-venv.sh for running tests without Docker [ci skip]

This commit is contained in:
Viktor Barzin 2026-02-14 11:44:49 +00:00
parent 556b5b0f42
commit 51e7a7ccc5
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 36 additions and 1 deletions

View file

@ -236,6 +236,6 @@ The project uses strict mypy configuration with `disallow_untyped_defs=true`. Ru
- Do not include unrelated files
- Use descriptive commit messages
- Group related files together (e.g., tests with the code they test)
- **Always run tests before committing**: `docker compose exec -T app pytest tests/ -v --tb=short`. If Docker is not available, use the local venv fallback: `/tmp/rec-test-venv/bin/pytest tests/ -v --tb=short` (set up with `python3 -m venv /tmp/rec-test-venv && /tmp/rec-test-venv/bin/pip install pytest pytest-asyncio pytest-cov httpx fakeredis aioresponses fastapi uvicorn sqlmodel sqlalchemy alembic pyjwt cryptography celery redis click aiohttp aiohttp-socks pillow numpy pytesseract opentelemetry-api opentelemetry-sdk opentelemetry-exporter-prometheus opentelemetry-instrumentation-fastapi opentelemetry-instrumentation-sqlalchemy python-dotenv webauthn apprise tenacity prometheus-client email-validator opencv-python-headless tqdm pandas cachetools watchdog`). If neither works, warn the user.
- **Always run tests before committing**: `docker compose exec -T app pytest tests/ -v --tb=short`. If Docker is not available, use the local venv fallback: `./scripts/setup-test-venv.sh && /tmp/rec-test-venv/bin/pytest tests/ -v --tb=short`. If neither works, warn the user.
- **After each meaningful change, ask the user if they want to commit and push the changes**

35
scripts/setup-test-venv.sh Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -eu
# Creates a lightweight Python venv for running tests locally (without Docker).
# Skips mysqlclient (needs system MySQL libs) — tests use SQLite in-memory.
#
# Usage: ./scripts/setup-test-venv.sh
# /tmp/rec-test-venv/bin/pytest tests/ -v --tb=short
VENV_DIR="/tmp/rec-test-venv"
if [ -x "$VENV_DIR/bin/pytest" ]; then
echo "Test venv already exists at $VENV_DIR"
echo "Run tests with: $VENV_DIR/bin/pytest tests/ -v --tb=short"
exit 0
fi
echo "Creating test venv at $VENV_DIR..."
python3 -m venv "$VENV_DIR"
echo "Installing dependencies..."
"$VENV_DIR/bin/pip" install --quiet --upgrade pip
"$VENV_DIR/bin/pip" install --quiet \
pytest pytest-asyncio pytest-cov httpx fakeredis aioresponses \
fastapi uvicorn sqlmodel sqlalchemy alembic pyjwt cryptography \
celery redis click aiohttp aiohttp-socks pillow numpy pytesseract \
opentelemetry-api opentelemetry-sdk opentelemetry-exporter-prometheus \
opentelemetry-instrumentation-fastapi opentelemetry-instrumentation-sqlalchemy \
python-dotenv webauthn apprise tenacity prometheus-client \
email-validator opencv-python-headless tqdm pandas cachetools watchdog
echo ""
echo "Done. Run tests with:"
echo " $VENV_DIR/bin/pytest tests/ -v --tb=short"