def db(): db = SqliteDatabase(':memory:') with db: Job.bind(db) Job.create_table() yield db Job.drop_table()
def db(): # Using tmp file because we need to test opening and closing a db conn # here and the :memory: sqlite db ceases to exist with the conn closed tmp_file = NamedTemporaryFile(delete=False) db_path = Path(tmp_file.name) tmp_file.close() db = SqliteDatabase(tmp_file.name) with db: Job.bind(db) Job.create_table() yield db if db_path.exists(): db_path.unlink()