Mercurial > p > roundup > code
changeset 8427:b34c3b8338f0
test: more fun with logger leakage.
I have disabled all calls to dictConfig. I can't see how to stop this
from leaking.
I even tried storing the root and roundup logger state (copying lists)
before running anything and restoring afterwards.
the funny part is if I removae all dictConfig calls and keep the state
saving and logger reset and restoring code it sill fails.
It passes if I don't restore the handler state for the root logger.
However the test will fail even when I comment out the root logger
config in the dict if I apply the dict. ????
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 20 Aug 2025 16:13:52 -0400 |
| parents | cd0edc091b97 |
| children | cdf876bcd370 |
| files | test/test_config.py |
| diffstat | 1 files changed, 54 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_config.py Wed Aug 20 12:53:14 2025 -0400 +++ b/test/test_config.py Wed Aug 20 16:13:52 2025 -0400 @@ -1139,6 +1139,20 @@ } """) + # save roundup logger state + loggernames = ("", "roundup") + logger_state = {} + for name in loggernames: + logger_state[name] = {} + + roundup_logger = logging.getLogger("roundup") + for i in ("filters", "handlers", "level", "propagate"): + attr = getattr(roundup_logger, i) + if isinstance(attr, list): + logger_state[name][i] = attr.copy() + else: + logger_state[name][i] = getattr(roundup_logger, i) + log_config_filename = self.instance.tracker_home \ + "/_test_log_config.json" @@ -1203,6 +1217,16 @@ ) ''' + ''' + # comment out as it breaks the logging config for caplog + # on test_rest.py:testBadFormAttributeErrorException + # for all rdbms backends. + # the log ERROR check never gets any info + + # commenting out root logger in config doesn't make it work. + # storing root logger and roundup logger state and restoring it + # still fails. + # happy path for init_logging() # verify preconditions @@ -1295,9 +1319,38 @@ ) ) - # rip down all the loggers leaving the root logger reporting to stdout. + ''' + # rip down all the loggers leaving the root logger reporting + # to stdout. # otherwise logger config is leaking to other tests + roundup_loggers = [logging.getLogger(name) for name in + logging.root.manager.loggerDict + if name.startswith("roundup")] + + # cribbed from configuration.py:init_loggers + hdlr = logging.StreamHandler(sys.stdout) + formatter = logging.Formatter( + '%(asctime)s %(levelname)s %(message)s') + hdlr.setFormatter(formatter) + + for logger in roundup_loggers: + # no logging API to remove all existing handlers!?! + for h in logger.handlers: + h.close() + logger.removeHandler(h) + logger.handlers = [hdlr] + logger.setLevel("DEBUG") + logger.propagate = True + + for name in loggernames: + local_logger = logging.getLogger(name) + for attr in logger_state[name]: + # if I restore handlers state for root logger + # I break the test referenced above. -- WHY???? + if attr == "handlers" and name == "": continue + setattr(local_logger, attr, logger_state[name][attr]) + from importlib import reload logging.shutdown() reload(logging)
