Mercurial > moin > 1.9
changeset 2954:96319d867986
enable logging to stderr with py.test tests
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Fri, 30 Nov 2007 15:30:20 +0100 |
parents | 41138237f2a5 |
children | c8a3731ce61c |
files | MoinMoin/conftest.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/conftest.py Fri Nov 30 14:58:20 2007 +0100 +++ b/MoinMoin/conftest.py Fri Nov 30 15:30:20 2007 +0100 @@ -23,6 +23,7 @@ from inspect import isclass from sys import modules import sys +import logging import py @@ -86,6 +87,23 @@ return request +def init_test_logging(loglevel_stderr=logging.DEBUG): + """ initialize python stdlib logging framework to output stuff to stderr """ + logger = logging.getLogger('') # root logger + logger.setLevel(logging.NOTSET) # otherwise it has WARNING by default! + + # define a Handler which writes to sys.stderr + logstderr = logging.StreamHandler() + logstderr.setLevel(loglevel_stderr) + # set a format which is simpler for console use + formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%H%M%S') + # tell the handler to use this format + logstderr.setFormatter(formatter) + # add the handler to the root logger + logger.addHandler(logstderr) + + logging.info("logging initialized") + class TestConfig: """ Custom configuration for unit tests @@ -191,6 +209,7 @@ Function = MoinTestFunction def __init__(self, *args, **kwargs): + init_test_logging() self.request = init_test_request() super(Module, self).__init__(*args, **kwargs)