Commit b16acb6c authored by Jérome Perrin's avatar Jérome Perrin

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.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19695 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5dcb6454
...@@ -299,24 +299,32 @@ def runUnitTestList(test_list, verbosity=1, debug=0): ...@@ -299,24 +299,32 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
suite = ERP5TypeTestLoader(save=save).loadTestsFromNames(test_list) suite = ERP5TypeTestLoader(save=save).loadTestsFromNames(test_list)
# Hack the profiler to run only specified test methods, and wrap results when # 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', '') run_only = os.environ.get('run_only', '')
if not save: if not save:
test_method_list = run_only.split(',') test_method_list = run_only.split(',')
from Testing.ZopeTestCase import profiler
run_orig = profiler.Profiled.__call__
def run(self, result=None): def wrapped_run(run_orig):
if debug and result: # wrap the method that run the test to run test method only if its name
result = DebugTestResult(result) # matches the run_only spec and to provide post mortem debugging facility
if not test_method_list: def run(self, result=None):
return run_orig(self, result) if debug and result:
test_method_name = self.id().rsplit('.', 1)[-1] result = DebugTestResult(result)
for valid_test_method_name_re in test_method_list: if not test_method_list:
if re.search(valid_test_method_name_re, test_method_name):
return run_orig(self, result) 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
profiler.Profiled.__call__ = wrapped_run(profiler.Profiled.__call__)
from unittest import TestCase
TestCase.__call__ = wrapped_run(TestCase.__call__)
profiler.Profiled.__call__ = run
# change current directory to the test home, to create zLOG.log in this dir. # change current directory to the test home, to create zLOG.log in this dir.
os.chdir(tests_home) os.chdir(tests_home)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment