[Zope3-checkins] CVS: Zope3 - test.py:1.19

Jeremy Hylton jeremy@zope.com
Wed, 11 Dec 2002 16:49:58 -0500


Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv1854

Modified Files:
	test.py 
Log Message:
Add experimental -T option for code coverage with unit tests.

XXX This only works if trace.py is importable.  It lives in the Python
distribution's Tools/scripts directory and doesn't get installed
anywhere :-(.


=== Zope3/test.py 1.18 => 1.19 ===
--- Zope3/test.py:1.18	Wed Dec 11 12:24:28 2002
+++ Zope3/test.py	Wed Dec 11 16:49:58 2002
@@ -62,6 +62,12 @@
 
 -C  use pychecker
 
+-T  use trace module from Python for code coverage
+    XXX This only works if trace.py is explicitly added to PYTHONPATH.
+    The current utility writes coverage files to a directory named
+    coverage that is parallel to build.  It also prints a summary
+    to stdout.
+
 modfilter
 testfilter
     Case-sensitive regexps to limit which tests are run, used in search
@@ -362,6 +368,15 @@
     elif LOOP:
         while 1:
             runner(files, test_filter, debug)
+    elif TRACE:
+        coverdir = os.path.join(os.getcwd(),"coverage")
+        import trace
+        tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
+                             trace=0, count=1)
+        tracer.runctx("runner(files, test_filter, debug)",
+                      globals=globals(), locals=vars())
+        r = tracer.results()
+        r.write_results(show_missing=True, summary=True, coverdir=coverdir)
     else:
         runner(files, test_filter, debug)
 
@@ -376,6 +391,7 @@
     global VERBOSE
     global LOOP
     global GUI
+    global TRACE
     global debug
     global debugger
     global build
@@ -395,7 +411,7 @@
     progress = 0
 
     try:
-        opts, args = getopt.getopt(argv[1:], 'vpdDLbhCumg:G:', ['help'])
+        opts, args = getopt.getopt(argv[1:], 'vpdDLbhCumg:G:T', ['help'])
     except getopt.error, msg:
         print msg
         print "Try `python %s -h' for more information." % argv[0]
@@ -432,6 +448,8 @@
                 print "-G argument must be DEBUG_ flag, not", repr(v)
                 sys.exit(1)
             gcflags.append(v)
+        elif k == '-T':
+            TRACE = 1
 
     if gcthresh is not None:
         import gc