Ignore:
Timestamp:
3 Aug 2011, 22:26:10 (13 years ago)
Author:
uli
Message:

Add two logging-related test helpers: a function to retrieve all
registered logger names and another one that removes loggers from
global (Python) registry, if they are not contained in the list. In
tests you can use the former to determine the set of pre-test loggers
and the latter to remove all loggers added during tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/testing.py

    r6466 r6577  
    33import grok
    44import doctest
     5import logging
    56import os.path
    67import re
     
    1920FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer',
    2021                            allow_teardown=True)
     22
     23def get_all_loggers():
     24    """Get the keys of all logger defined globally.
     25    """
     26    return logging.root.manager.loggerDict.keys()
     27
     28def remove_new_loggers(old_loggers):
     29    """Remove the loggers in `old_loggers`.
     30
     31    `old_loggers` is a list of logger keys as returned by
     32    :func:`get_all_loggers`. All globally registered loggers whose
     33    name is not in `old_loggers` is removed.
     34    """
     35    new_loggers = [key for key in logging.root.manager.loggerDict
     36                   if key not in old_loggers]
     37    for key in new_loggers:
     38        del logging.root.manager.loggerDict[key]
     39    return
    2140
    2241def setUpZope(test=None):
Note: See TracChangeset for help on using the changeset viewer.