Skip to content

Commit

Permalink
ci: add support for to run tests with postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-fs committed Jun 25, 2024
1 parent fa0d471 commit a2f049d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[])
Expand Down

0 comments on commit a2f049d

Please sign in to comment.