[Erp5-report] r16639 - /erp5/trunk/products/ERP5Type/tests/runUnitTest.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Sep 27 04:32:07 CEST 2007


Author: yo
Date: Thu Sep 27 04:32:07 2007
New Revision: 16639

URL: http://svn.erp5.org?rev=16639&view=rev
Log:
Add --run-only to specify test methods which should run. Ignore an error from trying to make the stdio unbuffering.

Modified:
    erp5/trunk/products/ERP5Type/tests/runUnitTest.py

Modified: erp5/trunk/products/ERP5Type/tests/runUnitTest.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/runUnitTest.py?rev=16639&r1=16638&r2=16639&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/runUnitTest.py (original)
+++ erp5/trunk/products/ERP5Type/tests/runUnitTest.py Thu Sep 27 04:32:07 2007
@@ -52,6 +52,9 @@
                              dependency provider (ie, the name of the BT
                              containing ZSQLMethods matching the desired
                              catalog storage).
+  --run_only=STRING
+                             Run only specified test methods delimited with
+                             commas (e.g. testFoo,testBar).
 """
 
 def getUnitTestFile():
@@ -247,7 +250,17 @@
     PortalTestCase.tearDown = dummy_tearDown
   
   suite = ERP5TypeTestLoader(save=save).loadTestsFromNames(test_list)
-  
+
+  # Hack the TestCase to run only specified test methods.
+  run_only = os.environ.get('run_only')
+  if run_only:
+    test_method_list = run_only.split(',')
+    run_orig = unittest.TestCase.run
+    def run(self, **kw):
+      if id(self).rsplit('.', 1)[-1] in test_method_list:
+        return run_orig(self, **kw)
+    unittest.TestCase.run = run
+
   # change current directory to the test home, to create zLOG.log in this dir.
   os.chdir(tests_home)
   return TestRunner().run(suite)
@@ -270,7 +283,8 @@
         "erp5_catalog_storage=",
         "save",
         "load",
-        "email_from_address="] )
+        "email_from_address=",
+        "run_only="] )
   except getopt.GetoptError, msg:
     usage(sys.stderr, msg)
     sys.exit(2)
@@ -317,6 +331,8 @@
       os.environ["erp5_load_data_fs"] = "1"
     elif opt == "--erp5_catalog_storage":
       os.environ["erp5_catalog_storage"] = arg
+    elif opt == "--run-only":
+      os.environ["run_only"] = arg
 
   test_list = args
   if not test_list:
@@ -330,8 +346,11 @@
 
 if __name__ == '__main__':
   # Force stdin, stdout and stderr to be totally unbuffered.
-  sys.stdin = os.fdopen(0, "rb", 0)
-  sys.stdout = os.fdopen(1, "wb", 0)
-  sys.stderr = os.fdopen(2, "wb", 0)
+  try:
+    sys.stdin = os.fdopen(0, "rb", 0)
+    sys.stdout = os.fdopen(1, "wb", 0)
+    sys.stderr = os.fdopen(2, "wb", 0)
+  except OSError:
+    pass
 
   main()




More information about the Erp5-report mailing list