[Erp5-report] r19695 - /erp5/trunk/products/ERP5Type/tests/runUnitTest.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Mar 5 13:05:39 CET 2008
Author: jerome
Date: Wed Mar 5 13:05:37 2008
New Revision: 19695
URL: http://svn.erp5.org?rev=19695&view=rev
Log:
monkey patch unittest.TestCase.__call__ the same way we patch
profiler.Profiled.__call__ to have --run_only and -D options working for tests
using unittest.TestCase but not ERP5TypeTestCase.
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=19695&r1=19694&r2=19695&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/runUnitTest.py (original)
+++ erp5/trunk/products/ERP5Type/tests/runUnitTest.py Wed Mar 5 13:05:37 2008
@@ -299,24 +299,32 @@
suite = ERP5TypeTestLoader(save=save).loadTestsFromNames(test_list)
# Hack the profiler to run only specified test methods, and wrap results when
- # running in debug mode.
+ # running in debug mode. We also monkeypatch unittest.TestCase for tests that
+ # does not use ERP5TypeTestCase
run_only = os.environ.get('run_only', '')
if not save:
test_method_list = run_only.split(',')
+
+ def wrapped_run(run_orig):
+ # wrap the method that run the test to run test method only if its name
+ # matches the run_only spec and to provide post mortem debugging facility
+ def run(self, result=None):
+ if debug and result:
+ result = DebugTestResult(result)
+ if not test_method_list:
+ return run_orig(self, result)
+ test_method_name = self.id().rsplit('.', 1)[-1]
+ for valid_test_method_name_re in test_method_list:
+ if re.search(valid_test_method_name_re, test_method_name):
+ return run_orig(self, result)
+ return run
+
from Testing.ZopeTestCase import profiler
- run_orig = profiler.Profiled.__call__
-
- def run(self, result=None):
- if debug and result:
- result = DebugTestResult(result)
- if not test_method_list:
- return run_orig(self, result)
- test_method_name = self.id().rsplit('.', 1)[-1]
- for valid_test_method_name_re in test_method_list:
- if re.search(valid_test_method_name_re, test_method_name):
- return run_orig(self, result)
-
- profiler.Profiled.__call__ = run
+ profiler.Profiled.__call__ = wrapped_run(profiler.Profiled.__call__)
+ from unittest import TestCase
+ TestCase.__call__ = wrapped_run(TestCase.__call__)
+
+
# change current directory to the test home, to create zLOG.log in this dir.
os.chdir(tests_home)
More information about the Erp5-report
mailing list