Commit 913138f4 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Always enable logging for unittests



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: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent e1ea54e9
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment