comparison MoinMoin/conftest.py @ 3105:80e1a910a2f1

make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 21:43:47 +0100
parents 96319d867986
children c6e39279f83b
comparison
equal deleted inserted replaced
3102:a78bf6977df8 3105:80e1a910a2f1
17 17
18 @copyright: 2005 Nir Soffer, 2007 Alexander Schremmer 18 @copyright: 2005 Nir Soffer, 2007 Alexander Schremmer
19 @license: GNU GPL, see COPYING for details. 19 @license: GNU GPL, see COPYING for details.
20 """ 20 """
21 21
22 # here you can configure logging used while running the tests,
23 # see http://www.python.org/doc/lib/logging-config-fileformat.html
24 logging_defaults = {
25 'loglevel': 'DEBUG',
26 }
27 logging_config = """\
28 [loggers]
29 keys=root
30
31 [handlers]
32 keys=stderr
33
34 [formatters]
35 keys=screen
36
37 [logger_root]
38 level=%(loglevel)s
39 handlers=stderr
40
41 [handler_stderr]
42 class=StreamHandler
43 level=NOTSET
44 formatter=screen
45 args=(sys.stderr, )
46
47 [formatter_screen]
48 format=%(asctime)s %(name)s %(levelname)s %(message)s
49 datefmt=%H%M%S
50 class=logging.Formatter
51 """
52
22 import atexit 53 import atexit
23 from inspect import isclass 54 from inspect import isclass
24 from sys import modules 55 from sys import modules
25 import sys 56 import sys
26 import logging
27 57
28 import py 58 import py
29 59
30 60
31 rootdir = py.magic.autopath().dirpath() 61 rootdir = py.magic.autopath().dirpath()
85 request.html_formatter = HtmlFormatter(request) 115 request.html_formatter = HtmlFormatter(request)
86 request.formatter = request.html_formatter 116 request.formatter = request.html_formatter
87 return request 117 return request
88 118
89 119
90 def init_test_logging(loglevel_stderr=logging.DEBUG):
91 """ initialize python stdlib logging framework to output stuff to stderr """
92 logger = logging.getLogger('') # root logger
93 logger.setLevel(logging.NOTSET) # otherwise it has WARNING by default!
94
95 # define a Handler which writes to sys.stderr
96 logstderr = logging.StreamHandler()
97 logstderr.setLevel(loglevel_stderr)
98 # set a format which is simpler for console use
99 formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%H%M%S')
100 # tell the handler to use this format
101 logstderr.setFormatter(formatter)
102 # add the handler to the root logger
103 logger.addHandler(logstderr)
104
105 logging.info("logging initialized")
106
107 class TestConfig: 120 class TestConfig:
108 """ Custom configuration for unit tests 121 """ Custom configuration for unit tests
109 122
110 Some tests assume a specific configuration, and will fail if the wiki admin 123 Some tests assume a specific configuration, and will fail if the wiki admin
111 changed the configuration. For example, DateTime macro test assume 124 changed the configuration. For example, DateTime macro test assume
207 class Module(py.test.collect.Module): 220 class Module(py.test.collect.Module):
208 Class = MoinClassCollector 221 Class = MoinClassCollector
209 Function = MoinTestFunction 222 Function = MoinTestFunction
210 223
211 def __init__(self, *args, **kwargs): 224 def __init__(self, *args, **kwargs):
212 init_test_logging() 225 from MoinMoin.server import configureLogging
226 configureLogging(logging_config, logging_defaults)
213 self.request = init_test_request() 227 self.request = init_test_request()
214 super(Module, self).__init__(*args, **kwargs) 228 super(Module, self).__init__(*args, **kwargs)
215 229
216 def run(self, *args, **kwargs): 230 def run(self, *args, **kwargs):
217 if coverage is not None: 231 if coverage is not None: