diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 560aa17..c6fbbdd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,11 +25,24 @@ jobs: - { python: "3.12", os: "ubuntu-latest", session: "typeguard" } - { python: "3.12", os: "ubuntu-latest", session: "xdoctest" } - { python: "3.12", os: "ubuntu-latest", session: "docs-build" } - + services: + postgres: + image: postgres:15 + env: + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 env: NOXSESSION: ${{ matrix.session }} FORCE_COLOR: "1" PRE_COMMIT_COLOR: "always" + POSTGRESQL_PASSWORD: "postgres" steps: - name: Check out the repository diff --git a/noxfile.py b/noxfile.py index 4738ebc..20aa37d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -139,12 +139,25 @@ def safety(session: Session) -> None: @session(python=python_versions) -def tests(session: Session) -> None: +@nox.parametrize("database", ["sqlite", "postgresql"]) +def tests(session: Session, database: str) -> None: """Run the test suite.""" session.install(".") session.install("coverage[toml]", "pytest", "pygments", "pytest-django", "faker") + + db_args = [f"--db-vendor={database}"] + + if database == "postgresql": + session.install("psycopg2") + for setting in ["name", "user", "password", "host", "port"]: + value = os.getenv(f"postgresql_{setting}".upper()) + if value: + db_args.append(f"--db-{setting}={value}") + try: - session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs) + session.run( + "coverage", "run", "--parallel", "-m", "pytest", *db_args, *session.posargs + ) finally: if session.interactive: session.notify("coverage", posargs=[])