Skip to content

Refactor pytest CI architecture with parallel testing and coverage aggregation #72

Refactor pytest CI architecture with parallel testing and coverage aggregation

Refactor pytest CI architecture with parallel testing and coverage aggregation #72

Workflow file for this run

# This workflow will run tests using pytest and upload the coverage report to Codecov
# Run test with various Python versions and database drivers
name: Integration Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9","3.10","3.11","3.12"]
driver: ["pg8000", "psycopg2", "psycopg", "psycopg2cffi", "asyncpg"]
name: Test pgmq-sqlalchemy (Python ${{ matrix.python-version }}, Driver ${{ matrix.driver }})
env:
# Create unique database name for this combination
DB_NAME_RAW: pgmq_py${{ matrix.python-version }}_${{ matrix.driver }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Install uv
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: uv sync --extra dev
- name: Start PostgreSQL (first time only)
run: |
# Only start if not already running
if ! docker ps | grep -q pgmq_postgres; then
cp pgmq_postgres.template.env pgmq_postgres.env
cp pgmq_tests.template.env pgmq_tests.env
make start-db
fi
- name: Setup unique database for this test run
run: |
# Normalize database name (remove dots and hyphens)
# Note: We normalize in each step because GitHub Actions doesn't support
# computed environment variables that can be reused across steps
export DB_NAME=$(echo "$DB_NAME_RAW" | sed 's/\.//g' | sed 's/-/_/g')
# Create the database
docker compose exec -T pgmq_postgres psql -U postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};" || true
docker compose exec -T pgmq_postgres psql -U postgres -c "CREATE DATABASE ${DB_NAME};"
docker compose exec -T pgmq_postgres psql -U postgres -d ${DB_NAME} -c "CREATE EXTENSION IF NOT EXISTS pgmq CASCADE;"
- name: Run tests for specific driver
run: |
# Normalize database name (remove dots and hyphens)
export DB_NAME=$(echo "$DB_NAME_RAW" | sed 's/\.//g' | sed 's/-/_/g')
uv run pytest tests --driver=${{ matrix.driver }} --db-name=${DB_NAME} --cov=pgmq_sqlalchemy.queue --cov-report=xml
continue-on-error: true
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Cleanup database
if: always()
run: |
# Normalize database name (remove dots and hyphens)
export DB_NAME=$(echo "$DB_NAME_RAW" | sed 's/\.//g' | sed 's/-/_/g')
docker compose exec -T pgmq_postgres psql -U postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};" || true