ERP5 KM

JeromePerrin

Don't expect anything interesting here :)

Coverage with ERP5Type.tests.runUnitTest

This patch no longer apply on trunk. I keep this here as a reference.

This explains how coverage could be integrated using figleaf (using coverage.py is very similar). The first problem is that both of those tool cannot collect coverage information when using execfile (which is what runUnitTest does). Anyway, it's possible to start coverage collecting from the code, like with this patch:

Index: ERP5Type/tests/runUnitTest.py
===================================================================
--- ERP5Type/tests/runUnitTest.py       (révision 13588)
+++ ERP5Type/tests/runUnitTest.py       (copie de travail)
@@ -2,6 +2,7 @@
 import os
 import sys
 import getopt
+import atexit

 __doc__ = """%(program)s: unit test runner for the ERP5 Project

@@ -11,6 +12,8 @@
   -v, --verbose              produce verbose output
   -h, --help                 this help screen
   -p, --profile              print profiling results at the end
+  -c, --coverage             collect coverage data using figleaf ( found at
+                             http://darcs.idyll.org/~t/projects/figleaf )
   --portal_id=STRING         force id of the portal. Useful when using
                              --data_fs_path to run tests on an existing
                              Data.fs
@@ -216,13 +219,13 @@
 def main():
   try:
     opts, args = getopt.getopt(sys.argv[1:],
-        "hpv", ["help", "verbose", "profile", "portal_id=", "data_fs_path=",
+        "hpvc", ["help", "verbose", "profile", "portal_id=", "data_fs_path=",
         "recreate_catalog=", "erp5_sql_connection_string=",
         "cmf_activity_sql_connection_string=",
         "erp5_sql_deferred_connection_string=",
         "erp5_catalog_storage=",
         "save",
-        "load",
+        "load", "coverage",
         "email_from_address="] )
   except getopt.GetoptError, msg:
     usage(sys.stderr, msg)
@@ -233,6 +236,13 @@
   for opt, arg in opts:
     if opt in ("-v", "--verbose"):
       os.environ['VERBOSE'] = "1"
+    elif opt in ("-c", "--coverage"):
+      import figleaf
+      figleaf.start()
+      def stop_figleaf():
+        figleaf.stop()
+        figleaf.write_coverage('.figleaf')
+      atexit.register(stop_figleaf)
     elif opt in ("-h", "--help"):
       usage(sys.stdout)
       sys.exit()

Run tests and collect coverage using (~/zope/ is my instance home, adapt paths for your installation): ~/zope/Products/ERP5Type/tests/runUnitTest.py -c testERP5Type. This will store profiling info in ~/zope/unit_test/tests/.figleaf file. That's it.

Now you will want to use figleaf2html to produce report of % of covered code and annoted files. This will give info about file from Zope and CMF, this is not interesting here, for this we use --exclude-patterns with a file containing regexps to exclude files you are not interested. I used a file named exclude_file containing ^/usr/lib/.* and ran:

figleaf2html --exclude-patterns=exclude_file -d output ~/zope/unit_test/tests/.figleaf

This created an output directory with an index.html showing coverage score and all annotated files (lines in green were run, lines in red were not run).


CategoryHomepage

JeromePerrin (last edited 2008-02-20 14:57:42 by JeromePerrin)

Page
  • Immutable Page
  • Info
  • Attachments
User
Learn about new ERP5 releases,technical articles, events and more.

Subscribe to the monthly ERP5 Newsletter!