def db() -> t.Generator[Database, None, None]: uri = "sqlite://" echo = False _db = Database(uri, model_class=Model, echo=echo) _db.create_all() yield _db _db.close()
def filedb(tmp_path: Path) -> t.Generator[Database, None, None]: dbpath = tmp_path / "test.db" uri = f"sqlite:///{dbpath}" _db = Database(uri, model_class=Model) _db.create_all() yield _db _db.close()
def test_database_close__disposes_engine(filedb: Database): with mock_db(filedb): filedb.close() assert filedb.engine.dispose.called # type: ignore