[Zope3-checkins]
SVN: zope.testing/trunk/src/zope/testing/testrunner.
add support for --coverage switch (with tests)
Benji York
benji at zope.com
Mon Aug 15 00:18:27 EDT 2005
Log message for revision 37931:
add support for --coverage switch (with tests)
Changed:
U zope.testing/trunk/src/zope/testing/testrunner.py
U zope.testing/trunk/src/zope/testing/testrunner.txt
-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py 2005-08-15 00:18:45 UTC (rev 37930)
+++ zope.testing/trunk/src/zope/testing/testrunner.py 2005-08-15 04:17:57 UTC (rev 37931)
@@ -235,7 +235,26 @@
else:
# normal
- tests(result)
+ if options.coverage:
+ coverdir = os.path.join(os.getcwd(), options.coverage)
+ import trace, tempfile, cPickle
+ ignoremods = ["os", "posixpath", "stat"]
+ tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
+ ignoremods=ignoremods, trace=False,
+ count=True)
+
+ tracer.runctx('tests(result)', globals=globals(),
+ locals=vars())
+
+ r = tracer.results()
+ f = tempfile.NamedTemporaryFile()
+ cPickle.dump(r, f)
+ f.close()
+ print f.name
+ r.write_results(show_missing=False, summary=True,
+ coverdir=coverdir)
+ else:
+ tests(result)
t = time.time() - t
if options.verbose == 1 or options.progress:
print
@@ -1175,7 +1194,9 @@
return doctest.DocFileSuite('testrunner.txt', 'testrunner-edge-cases.txt',
setUp=setUp, tearDown=tearDown,
- checker=checker)
+ optionflags=doctest.ELLIPSIS
+ +doctest.NORMALIZE_WHITESPACE,
+ checker=checker, )
def main():
default = [
Modified: zope.testing/trunk/src/zope/testing/testrunner.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.txt 2005-08-15 00:18:45 UTC (rev 37930)
+++ zope.testing/trunk/src/zope/testing/testrunner.txt 2005-08-15 04:17:57 UTC (rev 37931)
@@ -83,7 +83,7 @@
- Adds the directory containing the zope package to the Python
path:
- >>> import os, sys
+ >>> import os.path, sys
>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
>>> sys.path.append(directory_with_tests)
@@ -1897,3 +1897,31 @@
If you want to use pdb from a test in a layer that is run as a
subprocess, then rerun the test runner selecting *just* that layer so
that it's not run as a subprocess.
+
+Code Coverage
+-------------
+
+If the --coverage option is used, test coverage reports will be generated. The
+directory name given as the parameter will be used to hold the reports.
+
+ >>> from zope.testing import testrunner
+ >>> sys.argv = 'test --coverage=coverage_dir'.split()
+ >>> testrunner.run(defaults)
+ Running unit tests:
+ ...
+ lines cov% module (path)
+ ... ...% zope.testing.testrunner (src/zope/testing/testrunner.py)
+ ...
+
+The directory specified with the --coverage option will have been created and
+will hold the coverage reports.
+
+ >>> os.path.exists('coverage_dir')
+ True
+ >>> os.listdir('coverage_dir')
+ ['<doctest testrunner-ex.sample1.sampletests.test122.cover']
+
+(We should clean up after ouselves.)
+
+ >>> import shutil
+ >>> shutil.rmtree('coverage_dir')
More information about the Zope3-Checkins
mailing list