[Zope3-checkins]
SVN: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
moving setup and teardown of coverage analysis and profiling to the
Christian Theune
ct at gocept.com
Sat May 3 14:50:39 EDT 2008
Log message for revision 86266:
moving setup and teardown of coverage analysis and profiling to the
corresponding methods
Changed:
U zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
-=-
Modified: zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py 2008-05-03 18:44:37 UTC (rev 86265)
+++ zope.testing/branches/ctheune-cleanup/src/zope/testing/testrunner/runner.py 2008-05-03 18:50:38 UTC (rev 86266)
@@ -89,21 +89,6 @@
# to make tests of the test runner work properly. :)
pdb.set_trace = real_pdb_set_trace
- if (self.options.profile
- and sys.version_info[:3] <= (2,4,1)
- and __debug__):
- self.options.output.error(
- 'Because of a bug in Python < 2.4.1, profiling '
- 'during tests requires the -O option be passed to '
- 'Python (not the test runner).')
- sys.exit()
-
- if self.options.coverage:
- tracer = TestTrace(test_dirs(self.options, {}), trace=False, count=True)
- tracer.start()
- else:
- tracer = None
-
if self.options.profile:
prof_prefix = 'tests_profile.'
prof_suffix = '.prof'
@@ -127,8 +112,8 @@
except EndRun:
failed = True
finally:
- if tracer:
- tracer.stop()
+ if self.tracer:
+ self.tracer.stop()
if self.options.profile:
profiler.disable()
profiler.finish()
@@ -137,20 +122,13 @@
# attempt to unlink a still-open file.
os.close(oshandle)
- self.shutdown_features()
-
if self.options.profile and not self.options.resume_layer:
stats = profiler.loadStats(prof_glob)
stats.sort_stats('cumulative', 'calls')
self.options.output.profiler_stats(stats)
- if tracer:
- coverdir = os.path.join(os.getcwd(), self.options.coverage)
- r = tracer.results()
- r.write_results(summary=True, coverdir=coverdir)
+ self.shutdown_features()
- doctest.set_unittest_reportflags(self.old_reporting_flags)
-
if failed and self.options.exitwithstatus:
sys.exit(1)
@@ -192,7 +170,24 @@
# Control reporting flags during run
self.old_reporting_flags = doctest.set_unittest_reportflags(0)
+ # Set up code coverage analysis
+ if self.options.coverage:
+ self.tracer = TestTrace(test_dirs(self.options, {}), trace=False, count=True)
+ self.tracer.start()
+ else:
+ self.tracer = None
+ # Setup profiling
+ if (self.options.profile
+ and sys.version_info[:3] <= (2,4,1)
+ and __debug__):
+ self.options.output.error(
+ 'Because of a bug in Python < 2.4.1, profiling '
+ 'during tests requires the -O option be passed to '
+ 'Python (not the test runner).')
+ sys.exit()
+
+
def find_tests(self):
pass
@@ -375,9 +370,15 @@
return bool(import_errors or failures or errors)
def shutdown_features(self):
- pass
+ if self.tracer:
+ coverdir = os.path.join(os.getcwd(), self.options.coverage)
+ r = self.tracer.results()
+ r.write_results(summary=True, coverdir=coverdir)
+ doctest.set_unittest_reportflags(self.old_reporting_flags)
+
+
def run_tests(options, tests, name, failures, errors):
repeat = options.repeat or 1
repeat_range = iter(range(repeat))
More information about the Zope3-Checkins
mailing list