From 399c51a5e90d846cb936b9ebf8ac18c50f679632 Mon Sep 17 00:00:00 2001 From: Bruno FS Ciconelle Date: Mon, 8 Jul 2024 14:20:58 -0300 Subject: [PATCH] ci(noxfile): fix and DRY test dependencies --- noxfile.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 8c7032e..79f8989 100644 --- a/noxfile.py +++ b/noxfile.py @@ -36,6 +36,16 @@ ) +TEST_DEPENDENCIES = [ + "coverage[toml]", + "deepdiff", + "faker", + "pygments", + "pytest", + "pytest-django", +] + + def activate_virtualenv_in_precommit_hooks(session: Session) -> None: """Activate virtualenv in hooks installed by pre-commit. @@ -142,13 +152,12 @@ def safety(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") + dependencies = TEST_DEPENDENCIES.copy() db_args = [f"--db-vendor={database}"] if database == "postgresql": - session.install("psycopg2") + dependencies.append("psycopg2") if not os.getenv("POSTGRESQL_PASSWORD"): session.skip("no postgresql password provided. skipping...") for setting in ["name", "user", "password", "host", "port"]: @@ -156,6 +165,9 @@ def tests(session: Session, database: str) -> None: if value: db_args.append(f"--db-{setting}={value}") + session.install(".") + session.install(*dependencies) + try: session.run( "coverage", "run", "--parallel", "-m", "pytest", *db_args, *session.posargs @@ -181,8 +193,11 @@ def coverage(session: Session) -> None: @session(python=python_versions[0]) def typeguard(session: Session) -> None: """Runtime type checking using Typeguard.""" + dependencies = TEST_DEPENDENCIES.copy() + dependencies.append("typeguard") + session.install(".") - session.install("pytest", "typeguard", "pygments") + session.install(*dependencies) session.run("pytest", f"--typeguard-packages={package}", *session.posargs)