mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-13 15:58:46 +02:00
Testing speedup with in memory SQLite (#189)
If no SQLite File is written and deleted testing is MUCH faster.
This commit is contained in:
parent
aa6c0efc87
commit
030ad00c7d
@ -1,12 +1,10 @@
|
||||
"""Global configurations and definitions for pytest."""
|
||||
import datetime
|
||||
import os
|
||||
from collections.abc import Generator
|
||||
from inspect import getmembers, isfunction
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.engine import Engine
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from aki_prj23_transparenzregister.config.config_template import SQLiteConnectionString
|
||||
@ -41,20 +39,12 @@ def _clear_caches() -> Generator[None, None, None]:
|
||||
@pytest.fixture()
|
||||
def empty_db() -> Generator[Session, None, None]:
|
||||
"""Generates a db Session to a sql_lite db."""
|
||||
if os.path.exists("test-db.db"):
|
||||
os.remove("test-db.db")
|
||||
db = sessionmaker(
|
||||
autocommit=False,
|
||||
autoflush=False,
|
||||
bind=get_engine(SQLiteConnectionString("test-db.db")),
|
||||
)()
|
||||
engine = get_engine(SQLiteConnectionString(":memory:"))
|
||||
db = sessionmaker(autocommit=False, autoflush=False, bind=engine)()
|
||||
init_db(db)
|
||||
yield db
|
||||
db.close()
|
||||
bind = db.bind
|
||||
assert isinstance(bind, Engine)
|
||||
bind.dispose()
|
||||
os.remove("test-db.db")
|
||||
engine.dispose()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
Loading…
x
Reference in New Issue
Block a user