I need to disable alembic migrations logging, while executing migrations in unit tests, .
I can't just remove alembic
logger it from alembic.ini
: i need this output while performing migrations myself.
Following did not work for me:
logging.getLogger('alembic').setLevel(logging.CRITICAL)
How i can disable it at runtime?
If you want to run to downgrade() of a version, you will need to run alembic downgrade the-version-before-it , which mean it will revert to the version after the version that you want to downgrade. Which is the version before the version that we want to revert.
yourproject - this is the root of your application's source code, or some directory within it. alembic - this directory lives within your application's source tree and is the home of the migration environment.
This is where we will write our migrations. Alembic created a unique id and empty upgrade and downgrade functions. Upgrade contains the code that executes when we run our migration whereas downgrade contains the code executed when we rollback a migration.
alembic init alembic From there, you can create tables or migrate functions for example. After the init command, a folder structure is created. The file named 'alembic.ini' is called every time Alembic is used. It contains all the basic information that makes it possible to connect to the database of your choice.
You need to edit the alembic.ini file and change the logging setting for this particular log. You can read about it in the relevant section of the Alembic tutorial. By default, this section should be in your configuration file:
[logger_alembic]
level = INFO
handlers =
qualname = alembic
I set mine to WARN
instead, and these logs went away.
Sounds like you're invoking Alembic from within your unit tests by calling out to the alembic
command, which is a separate process and does not inherit your logging configuration.
Instead, you should invoke Alembic programmatically:
import logging
import alembic.config
import alembic.command
logging.getLogger('alembic').setLevel(logging.CRITICAL)
alembic_cfg = alembic.config.Config('alembic.ini')
alembic.command.upgrade(alembic_cfg, 'head')
See the documentation for more info about the Alembic API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With