Some alembic commands (for example, upgrade and downgrade) create an engine and a connection, but these resources are not cleaned up on exit. I have some tests that create a new database, run alembic commands, and finally drop the database. However, the database cannot be dropped until the alembic resources are cleaned up. These resources are created in env.py. Should the env.py templates include some resource cleanup?
engine = engine_from_config( config.get_section(config.config_ini_section), prefix='sqlalchemy.')
connection = engine.connect() try: context.configure( connection=connection, target_metadata=target_metadata )
with context.begin_transaction(): context.run_migrations()
finally: connection.close() engine.dispose() }}}