I am using logbook for my applications logging, python's unittest for testing, and tox for running my tests in jenkins. Logging that is helpful for production is very distracting when analyzing my tests output. Is it possible to suppress logging while running tests?
1 Answer
Option 1:
Switch your test runner to pytest, which captures/suppresses logging by default. Note that pytest runner can and will still collect tests written with stdlib unittest.
Option 2:
Mock out the logging configuration to use a NullHandler
during test execution. This means that, during a test run, the logging which would otherwise go to file and/or stderr will instead go... nowhere. You can not use this approach if you actually want to make assertions on logged events, for that you will need to configure a log capturing handler, such as MemoryHandler
.