Index: src/zope/testing/testrunner.py =================================================================== --- src/zope/testing/testrunner.py (revision 81407) +++ src/zope/testing/testrunner.py (working copy) @@ -39,6 +39,8 @@ import unittest +before_tests_hooks = [] +after_tests_hooks = [] available_profilers = {} try: @@ -925,7 +927,8 @@ # set up the output file oshandle, file_path = tempfile.mkstemp(prof_suffix, prof_prefix, '.') profiler = available_profilers[options.profile](file_path) - profiler.enable() + before_tests_hooks.append(profiler.enable) + after_tests_hooks.append(profiler.disable) try: try: @@ -936,7 +939,6 @@ if tracer: tracer.stop() if options.profile: - profiler.disable() profiler.finish() # We must explicitly close the handle mkstemp returned, else on # Windows this dies the next time around just above due to an @@ -1259,7 +1261,10 @@ errors.append((SetUpLayerFailure(), sys.exc_info())) return 0 else: - return run_tests(options, tests, layer_name, failures, errors) + [hook() for hook in before_tests_hooks] + results = run_tests(options, tests, layer_name, failures, errors) + [hook() for hook in after_tests_hooks] + return results class SetUpLayerFailure(unittest.TestCase): def runTest(self):