Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run alembic migrations instead of using sqlalchemy to migrate test db #169

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import datetime as dt
import json
import os.path
import uuid
from pathlib import Path
from typing import List

import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from testcontainers.postgres import PostgresContainer

from alembic import command
from alembic.config import Config
from pvsite_datamodel import ClientSQL, GenerationSQL, SiteSQL, StatusSQL
from pvsite_datamodel.sqlmodels import Base
from pvsite_datamodel.write.user_and_site import create_site_group, create_user

PROJECT_PATH = Path(__file__).parent.parent.resolve()


@pytest.fixture(scope="session")
def engine():
Expand All @@ -22,7 +27,14 @@ def engine():
# TODO need to setup postgres database with docker
url = postgres.get_connection_url()
engine = create_engine(url)
Base.metadata.create_all(engine)

# run alembic migrations
ini_path = os.path.join(PROJECT_PATH, "alembic.ini")
alembic_cfg = Config(file_=ini_path)
alembic_dir = os.path.join(PROJECT_PATH, "alembic")
alembic_cfg.set_main_option("script_location", alembic_dir)
os.environ["DB_URL"] = url
command.upgrade(alembic_cfg, "head")

yield engine

Expand Down
Loading