Add tests and fix issues
This commit is contained in:
34
tests/conftest.py
Normal file
34
tests/conftest.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from alembic import config
|
||||
from pytest_alembic.config import Config
|
||||
from streamlit.testing.v1 import AppTest
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_database(alembic_runner):
|
||||
logger.info("Running database migrations")
|
||||
alembic_runner.migrate_up_to('heads')
|
||||
yield
|
||||
logger.info("Resetting database")
|
||||
alembic_runner.migrate_down_to('base')
|
||||
|
||||
@pytest.fixture
|
||||
def alembic_config() -> Config:
|
||||
logging.info("Setting up alembic config")
|
||||
alembic_cfg = config.Config(toml_file="pyproject.toml")
|
||||
alembic_cfg.set_main_option("sqlalchemy.url", os.getenv("DATABASE_URL", ""))
|
||||
return Config(alembic_config=alembic_cfg)
|
||||
|
||||
@pytest.fixture
|
||||
def app() -> AppTest:
|
||||
return AppTest.from_file("app/streamlit_app.py")
|
||||
|
||||
def delete_database():
|
||||
file = os.getenv("DATABASE_FILE")
|
||||
if file and os.path.isfile(file):
|
||||
logger.info(f"Deleting database file {file}")
|
||||
os.remove(file)
|
||||
Reference in New Issue
Block a user