Commit 495b65c7 authored by icemac's avatar icemac

``zc.buildout.testing.buildoutSetUp`` installs a new handler in the python...

``zc.buildout.testing.buildoutSetUp`` installs a new handler in the python root logging facility. This handler is now removed during tear down as it might disturb other packages reusing buildout's testing infrastructure.



git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@99819 62d5b8a3-27da-0310-9561-8e5933582275
parent 9fd8ce47
......@@ -5,9 +5,16 @@ Change History
==================
- Better Windows compatibility in test infrastructure.
- Now the bootstrap.py has an optional --version argument,
that can be used to force zc.buildout version to use.
- ``zc.buildout.testing.buildoutSetUp`` installs a new handler in the
python root logging facility. This handler is now removed during
tear down as it might disturb other packages reusing buildout's
testing infrastructure.
1.2.1 (2009-03-18)
==================
......
......@@ -18,6 +18,7 @@ $Id$
import BaseHTTPServer
import errno
import logging
import os
import pkg_resources
import random
......@@ -210,6 +211,14 @@ def buildoutSetUp(test):
here = os.getcwd()
register_teardown(lambda: os.chdir(here))
handlers_before_set_up = logging.getLogger().handlers[:]
def restore_root_logger_handlers():
root_logger = logging.getLogger()
for handler in root_logger.handlers[:]:
root_logger.removeHandler(handler)
for handler in handlers_before_set_up:
root_logger.addHandler(handler)
register_teardown(restore_root_logger_handlers)
base = tempfile.mkdtemp('buildoutSetUp')
base = os.path.realpath(base)
......
Bug fixes in zc.buildout.testing
================================
Logging handler which did not get deleted
-----------------------------------------
The buildout testing set up runs a buildout which adds a
``logging.StreamHandler`` to the root logger. But tear down did not
remove it. This can disturb other tests of packages reusing
zc.buildout.testing.
The handers before calling set up are:
>>> import logging
>>> len(logging.getLogger().handlers)
1
>>> logging.getLogger().handlers # doctest: +ELLIPSIS
[<zope.testing.testrunner.logsupport.NullHandler instance at ...>]
After calling it, a ``logging.StreamHandler`` was added:
>>> import zc.buildout.testing
>>> import doctest
>>> test = doctest.DocTestParser().get_doctest(
... '>>> x', {}, 'foo', 'foo.py', 0)
>>> zc.buildout.testing.buildoutSetUp(test)
>>> len(logging.getLogger().handlers)
2
>>> logging.getLogger().handlers # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
[<zope.testing.testrunner.logsupport.NullHandler instance at ...>,
<logging.StreamHandler instance at ...>]
But tear down removes the new logging handler:
>>> zc.buildout.testing.buildoutTearDown(test)
>>> len(logging.getLogger().handlers)
1
>>> logging.getLogger().handlers # doctest: +ELLIPSIS
[<zope.testing.testrunner.logsupport.NullHandler instance at ...>]
This diff is collapsed.
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