1

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?

0

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.