Sometimes you need to assert log traces while writing tests, mostly functional tests (end to end) after you have setup several components by means of mocks. When executing nosetests it sets up automatically the logging and uses any handler you provide on your own.
Let’s say you have got a module in your tests folder including the following code:
then, in a test case you could end up writing something like:
Overall, it shows how easy it is to assert log traces in-memory while executing unittests. In a similar way you could patch the sys STDOUT with a mock object providing a write method and assert what is being written by means of print statements.