~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/__init__.py

  • Committer: Curtis Hovey
  • Date: 2011-12-28 17:03:06 UTC
  • mto: This revision was merged to the branch mainline in revision 14605.
  • Revision ID: curtis.hovey@canonical.com-20111228170306-n9fz94h85ckaoaf3
Separate test-authoring classes from test-running classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    'person_logged_in',
37
37
    'quote_jquery_expression',
38
38
    'record_statements',
 
39
    'reset_logging',
39
40
    'run_process',
40
41
    'run_script',
41
42
    'run_with_login',
71
72
    )
72
73
import logging
73
74
import os
74
 
from pprint import pformat
75
75
import re
76
76
from select import select
77
77
import shutil
176
176
    )
177
177
from lp.testing.fixture import CaptureOops
178
178
from lp.testing.karma import KarmaRecorder
 
179
import lp_sitecustomize
179
180
 
180
181
# The following names have been imported for the purpose of being
181
182
# exported. They are referred to here to silence lint warnings.
197
198
with_person_logged_in
198
199
 
199
200
 
 
201
def reset_logging():
 
202
    """Reset the logging system back to defaults
 
203
 
 
204
    Currently, defaults means 'the way the Z3 testrunner sets it up'
 
205
    plus customizations made in lp_sitecustomize
 
206
    """
 
207
    # Remove all handlers from non-root loggers, and remove the loggers too.
 
208
    loggerDict = logging.Logger.manager.loggerDict
 
209
    for name, logger in list(loggerDict.items()):
 
210
        if name == 'pagetests-access':
 
211
            # Don't reset the hit logger used by the test infrastructure.
 
212
            continue
 
213
        if not isinstance(logger, logging.PlaceHolder):
 
214
            for handler in list(logger.handlers):
 
215
                logger.removeHandler(handler)
 
216
        del loggerDict[name]
 
217
 
 
218
    # Remove all handlers from the root logger
 
219
    root = logging.getLogger('')
 
220
    for handler in root.handlers:
 
221
        root.removeHandler(handler)
 
222
 
 
223
    # Set the root logger's log level back to the default level: WARNING.
 
224
    root.setLevel(logging.WARNING)
 
225
 
 
226
    # Clean out the guts of the logging module. We don't want handlers that
 
227
    # have already been closed hanging around for the atexit handler to barf
 
228
    # on, for example.
 
229
    del logging._handlerList[:]
 
230
    logging._handlers.clear()
 
231
 
 
232
    # Reset the setup
 
233
    from zope.testing.testrunner.runner import Runner
 
234
    from zope.testing.testrunner.logsupport import Logging
 
235
    Logging(Runner()).global_setup()
 
236
    lp_sitecustomize.customize_logger()
 
237
 
 
238
 
200
239
class FakeTime:
201
240
    """Provides a controllable implementation of time.time().
202
241
 
594
633
        super(TestCase, self).setUp()
595
634
        # Circular imports.
596
635
        from lp.testing.factory import ObjectFactory
597
 
        from canonical.testing.layers import LibrarianLayer
 
636
        from lp.testing.layers import LibrarianLayer
598
637
        self.factory = ObjectFactory()
599
638
        # Record the oopses generated during the test run.
600
639
        # You can call self.oops_capture.sync() to collect oopses from
840
879
        # XXX wgrant 2011-03-09 bug=505913:
841
880
        # TestTwistedJobRunner.test_timeout fails if this is at the
842
881
        # module level. There is probably some hidden circular import.
843
 
        from canonical.testing.layers import AppServerLayer
 
882
        from lp.testing.layers import AppServerLayer
844
883
        return AppServerLayer
845
884
 
846
885
    def setUp(self):