diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 54186f8a..d1348b6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,6 +77,10 @@ jobs: poetry run black --check . poetry run flake8 + - name: Run db migration + run: | + CONFIG=tests/test.env poetry run alembic upgrade head + - name: Test with pytest run: | poetry run pytest diff --git a/scripts/run-test.sh b/scripts/run-test.sh index 2411221d..37599204 100644 --- a/scripts/run-test.sh +++ b/scripts/run-test.sh @@ -1,12 +1,19 @@ # Run tests +# Delete the test DB if it isn't properly removed docker rm -f sl-test-db +# Create a test DB docker run -d --name sl-test-db -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -p 15432:5432 postgres:13 -# the time the DB container starts +# the time for the test DB container to start sleep 3 +# migrate the DB to the latest version +CONFIG=tests/test.env poetry run alembic upgrade head + +# run test poetry run pytest +# Delete the test DB docker rm -f sl-test-db diff --git a/tests/conftest.py b/tests/conftest.py index 3a0d4abe..a8c5ce69 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ os.environ["CONFIG"] = os.path.abspath( import sqlalchemy from app.db import Session, engine, connection -from app.models import Base from psycopg2 import errors from psycopg2.errorcodes import DEPENDENT_OBJECTS_STILL_EXIST @@ -34,8 +33,6 @@ with engine.connect() as conn: print(">>> pg_trgm can't be dropped, ignore") conn.execute("Rollback") -Base.metadata.create_all(engine) - add_sl_domains()