def setup_layer(options, layer, setup_layers): assert layer is not object output = options.output if layer not in setup_layers: for base in layer.__bases__: if base is not object: setup_layer(options, base, setup_layers) output.start_set_up(name_from_layer(layer)) t = time.time() if hasattr(layer, 'setUp'): try: layer.setUp() except Exception: if options.post_mortem: if options.resume_layer: options.output.error_with_banner( cant_pm_in_subprocess_message % options.resume_layer) raise else: zope.testing.testrunner.debug.post_mortem( sys.exc_info()) else: raise output.stop_set_up(time.time() - t) setup_layers[layer] = 1
def order_by_bases(layers): """Order the layers from least to most specific (bottom to top) """ named_layers = [(name_from_layer(layer), layer) for layer in layers] named_layers.sort() named_layers.reverse() gathered = [] for name, layer in named_layers: gather_layers(layer, gathered) gathered.reverse() seen = {} result = [] for layer in gathered: if layer not in seen: seen[layer] = 1 if layer in layers: result.append(layer) return result
def tear_down_unneeded(options, needed, setup_layers, optional=False): # Tear down any layers not needed for these tests. The unneeded layers # might interfere. unneeded = [l for l in setup_layers if l not in needed] unneeded = order_by_bases(unneeded) unneeded.reverse() output = options.output for l in unneeded: output.start_tear_down(name_from_layer(l)) t = time.time() try: if hasattr(l, 'tearDown'): l.tearDown() except NotImplementedError: output.tear_down_not_supported() if not optional: raise CanNotTearDown(l) else: output.stop_tear_down(time.time() - t) del setup_layers[l]
def tear_down_unneeded(options, needed, setup_layers, optional=False): # Tear down any layers not needed for these tests. The unneeded layers # might interfere. unneeded = [l for l in setup_layers if l not in needed] unneeded = order_by_bases(unneeded) unneeded.reverse() output = options.output for l in unneeded: output.start_tear_down(name_from_layer(l)) t = time.time() try: try: if hasattr(l, 'tearDown'): l.tearDown() except NotImplementedError: output.tear_down_not_supported() if not optional: raise CanNotTearDown(l) else: output.stop_tear_down(time.time() - t) finally: del setup_layers[l]