In many cases unit-tests are significantly slowed down by the use of python’s logging package. Assuming logging isn’t essential to the test, how would you cleanly override logging per-test, so that log commands would be effectively skipped.
Assume the use of multiple loggers such as in:
logger1 = logging.getLogger('logger1')
logger2 = logging.getLogger('logger2')
Option 1:
Logging can be disabled by calling
and turned back on with
However, even after disabling logging, a logging statement such as
logger.infowould still cause Python to do a few attribute lookups and function calls before reaching theisEnabledFormethod. Still, this might be good enough.Option 2:
Use mocking:
This will reduce the time consumed by logging statements to the time it takes to do one attribute lookup and one (noop) function call. If that’s not satisfactory, I think the only option left is removing the logging statements themselves.