Proper way to delete/kill a logger?

Chris Withers chris at simplistix.co.uk
Mon Nov 28 02:13:15 EST 2011


On 28/11/2011 04:16, cassiope wrote:
> I've been trying to migrate some code to using the standard python
> logging classes/objects.  And they seem quite capable of doing what I
> need them to do.  Unfortunately there's a problem in my unit tests.
> It's fairly common to have to create quite a few entities in the
> course of a series of tests.  What appears to be happening is that the
> loggers don't get entirely eliminated, so that new invocations end up
> spewing output messages from each of the loggers that were started
> with this invocation of the python interpreter.

Two suggestions:

- unless you are specifically testing the logging set up of your 
application, your code under test shouldn't be setting up logging.

- if you want to check that your code under test is emitting log 
messages correctly, use a LogCapture from testfixtures:

http://packages.python.org/testfixtures.

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk



More information about the Python-list mailing list