From 913138f4b477abae0bb4f00eabb8ba246643483a Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 15 Sep 2010 20:23:01 +0200 Subject: [PATCH] Always enable logging for unittests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By enabling all log levels, we ensure all calls are fully evaluated. There was one case in the workerpool where a call to βlogging.debugβ was wrong, but not caught in unittests because debug logging was disabled. The optional environment variable βLOGTOSTDERRβ can be set to write all log messages to stderr instead of /dev/null. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- test/testutils.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/testutils.py b/test/testutils.py index fd4655a98..3c46a0cc1 100644 --- a/test/testutils.py +++ b/test/testutils.py @@ -35,12 +35,32 @@ def GetSourceDir(): return os.environ.get("TOP_SRCDIR", ".") +def _SetupLogging(verbose): + """Setupup logging infrastructure. + + """ + fmt = logging.Formatter("%(asctime)s: %(threadName)s" + " %(levelname)s %(message)s") + + if verbose: + handler = logging.StreamHandler() + else: + handler = logging.FileHandler(os.devnull, "a") + + handler.setLevel(logging.NOTSET) + handler.setFormatter(fmt) + + root_logger = logging.getLogger("") + root_logger.setLevel(logging.NOTSET) + root_logger.addHandler(handler) + + class GanetiTestProgram(unittest.TestProgram): def runTests(self): - """ + """Runs all tests. """ - logging.basicConfig(filename=os.devnull) + _SetupLogging("LOGTOSTDERR" in os.environ) sys.stderr.write("Running %s\n" % self.progName) sys.stderr.flush() -- GitLab