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,13 +299,15 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
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(',')
from Testing.ZopeTestCase import profiler
run_orig = profiler.Profiled.__call__
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)
......@@ -315,8 +317,14 @@ def runUnitTestList(test_list, verbosity=1, debug=0):
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.
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