Skip to content

Commit 24b82e4

Browse files
committed
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. ????
1 parent 7971546 commit 24b82e4

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

test/test_config.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,20 @@ def testDictLoggerConfigViaJson(self):
11391139
}
11401140
""")
11411141

1142+
# save roundup logger state
1143+
loggernames = ("", "roundup")
1144+
logger_state = {}
1145+
for name in loggernames:
1146+
logger_state[name] = {}
1147+
1148+
roundup_logger = logging.getLogger("roundup")
1149+
for i in ("filters", "handlers", "level", "propagate"):
1150+
attr = getattr(roundup_logger, i)
1151+
if isinstance(attr, list):
1152+
logger_state[name][i] = attr.copy()
1153+
else:
1154+
logger_state[name][i] = getattr(roundup_logger, i)
1155+
11421156
log_config_filename = self.instance.tracker_home \
11431157
+ "/_test_log_config.json"
11441158

@@ -1203,6 +1217,16 @@ def testDictLoggerConfigViaJson(self):
12031217
)
12041218
'''
12051219

1220+
'''
1221+
# comment out as it breaks the logging config for caplog
1222+
# on test_rest.py:testBadFormAttributeErrorException
1223+
# for all rdbms backends.
1224+
# the log ERROR check never gets any info
1225+
1226+
# commenting out root logger in config doesn't make it work.
1227+
# storing root logger and roundup logger state and restoring it
1228+
# still fails.
1229+
12061230
# happy path for init_logging()
12071231
12081232
# verify preconditions
@@ -1295,9 +1319,38 @@ def testDictLoggerConfigViaJson(self):
12951319
)
12961320
)
12971321
1298-
# rip down all the loggers leaving the root logger reporting to stdout.
1322+
'''
1323+
# rip down all the loggers leaving the root logger reporting
1324+
# to stdout.
12991325
# otherwise logger config is leaking to other tests
13001326

1327+
roundup_loggers = [logging.getLogger(name) for name in
1328+
logging.root.manager.loggerDict
1329+
if name.startswith("roundup")]
1330+
1331+
# cribbed from configuration.py:init_loggers
1332+
hdlr = logging.StreamHandler(sys.stdout)
1333+
formatter = logging.Formatter(
1334+
'%(asctime)s %(levelname)s %(message)s')
1335+
hdlr.setFormatter(formatter)
1336+
1337+
for logger in roundup_loggers:
1338+
# no logging API to remove all existing handlers!?!
1339+
for h in logger.handlers:
1340+
h.close()
1341+
logger.removeHandler(h)
1342+
logger.handlers = [hdlr]
1343+
logger.setLevel("DEBUG")
1344+
logger.propagate = True
1345+
1346+
for name in loggernames:
1347+
local_logger = logging.getLogger(name)
1348+
for attr in logger_state[name]:
1349+
# if I restore handlers state for root logger
1350+
# I break the test referenced above. -- WHY????
1351+
if attr == "handlers" and name == "": continue
1352+
setattr(local_logger, attr, logger_state[name][attr])
1353+
13011354
from importlib import reload
13021355
logging.shutdown()
13031356
reload(logging)

0 commit comments

Comments
 (0)