[docs]@pytest.fixtureasyncdefsql_engine(database_url,test_id)->AsyncEngine:""" Use a DMBS conncetion string to create a sqlalchemy async engine to a new isolated database that will gets an initial status/structure/schema by executing migrations on it, whatever the migration process is for the given URL (for example, sqlite will use a simple create_all strategy, while postgres or mysql will use alembic). This looks a bit overkill, but this is the simplest way to guarantee isolated and repeatable tests that depends on databases. The isolated database name will be based on the test_id fixture value, which will create an unique hash string for each test. """asyncwithget_scoped_database_url(database_url,test_id)asscoped_database_url:engine=create_async_engine(scoped_database_url)try:# todo refactor (dup in sqlstorage.initialize / sqlstorage._run_migrations)alembic_cfg=create_alembic_config(engine.url.render_as_string(hide_password=False))migrator=partial(command.upgrade,alembic_cfg,"head")awaitdo_migrate(engine,migrator=migrator)yieldenginefinally:awaitengine.dispose()
[docs]@pytest.fixtureasyncdefsql_storage(sql_engine,blob_storage)->SqlStorage:storage=SqlStorage(sql_engine,blob_storage=blob_storage,settings=StorageSettings(**(DEFAULT_STORAGE_SETTINGS|{"url":sql_engine.url})),)# migrations are disabled because already done by the sql_engine fixture, but we still need to do additional# initialization steps.awaitstorage.initialize()yieldstorage