live test improvements: reload test modules also when specifying test classes...

live test improvements: reload test modules also when specifying test classes in the test list (like 'testPackingList.TestPackingList') plus some cleanup and refactoring

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44362 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ff65d924
......@@ -1203,6 +1203,17 @@ def initialize( context ):
result = global_stream.read()
return result
security.declarePrivate('_getCommaSeparatedParameterList')
def _getCommaSeparatedParameterList(self, parameter_list):
# clean parameter_list and split it by commas if necessary
if not parameter_list:
parameter_list = ()
elif isinstance(parameter_list, basestring):
parameter_list = tuple(parameter_name.strip()
for parameter_name in parameter_list.split(',')
if parameter_name.strip())
return parameter_list
security.declareProtected(Permissions.ManagePortal, 'runLiveTest')
def runLiveTest(self, test_list=None, run_only=None, debug=False,
verbose=False):
......@@ -1218,18 +1229,22 @@ def initialize( context ):
# Allow having strings for verbose and debug
verbose = int(verbose) and True or False
debug = int(debug) and True or False
if test_list is None:
test_list = []
elif isinstance(test_list, str):
test_list = test_list.split(',')
test_list = self._getCommaSeparatedParameterList(test_list)
run_only = self._getCommaSeparatedParameterList(run_only)
if not test_list:
# no test to run
return ''
path = os.path.join(getConfiguration().instancehome, 'tests')
verbosity = verbose and 2 or 1
instance_home = getConfiguration().instancehome
global global_stream
global_stream = StringIO()
from Products.ERP5Type.tests.ERP5TypeLiveTestCase import runLiveTest
result = runLiveTest(test_list, run_only=run_only, debug=debug, path=path,
stream=global_stream, verbosity=verbosity)
result = runLiveTest(test_list,
run_only=run_only,
debug=debug,
path=path,
stream=global_stream,
verbosity=verbosity)
global_stream.seek(0)
return global_stream.read()
......
......@@ -132,18 +132,37 @@ from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader
class ERP5TypeTestReLoader(ERP5TypeTestLoader):
def __init__(self, filter_test_list=()):
super(ERP5TypeTestReLoader, self).__init__()
if len(filter_test_list):
# do not filter if no filter, otherwise no tests run
self.filter_test_list = filter_test_list
def loadTestsFromModule(self, module):
"""ERP5Type test re-loader supports reloading test modules before
running them.
"""
reload(module)
return super(ERP5TypeTestReLoader, self).loadTestsFromModule(module)
def __init__(self, filter_test_list=()):
super(ERP5TypeTestReLoader, self).__init__()
if len(filter_test_list):
# do not filter if no filter, otherwise no tests run
self.filter_test_list = filter_test_list
def loadTestsFromNames(self, test_list):
# ERP5TypeTestLoader is monkey-patched into unittest
# so we have to monkeypatch it in turn
if self.filter_test_list is not None:
old_filter_test_list = ERP5TypeTestLoader.filter_test_list
ERP5TypeTestLoader.filter_test_list = self.filter_test_list
try:
return super(ERP5TypeTestReLoader,
self).loadTestsFromNames(test_list)
finally:
# and undo the monkeypatch afterwards
if self.filter_test_list:
ERP5TypeTestLoader.filter_test_list = old_filter_test_list
def loadTestsFromModule(self, module):
"""ERP5Type test re-loader supports reloading test modules before
running them.
"""
reload(module)
return super(ERP5TypeTestReLoader, self).loadTestsFromModule(module)
def loadTestsFromTestCase(self, testCaseClass):
reload(sys.modules[testCaseClass.__module__])
return super(ERP5TypeTestReLoader,
self).loadTestsFromTestCase(testCaseClass)
def runLiveTest(test_list, verbosity=1, stream=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult
......@@ -171,19 +190,11 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
result = super(DebugTextTestRunner, self)._makeResult()
return DebugTestResult(result)
TestRunner = DebugTextTestRunner
run_only = kw.get('run_only', '').strip()
filter_test_list = [re.compile(x.strip()).search
for x in run_only.split(',')]
loader = ERP5TypeTestReLoader()
# ERP5TypeTestLoader is monkey-patched into unittest
# so we have to monkeypatch it
if filter_test_list:
old_filter_test_list = ERP5TypeTestLoader.filter_test_list
ERP5TypeTestLoader.filter_test_list = filter_test_list
run_only = kw.get('run_only', ())
filter_test_list = [re.compile(x).search
for x in run_only]
loader = ERP5TypeTestReLoader(filter_test_list)
suite = loader.loadTestsFromNames(test_list)
# and undo the monkeypatch afterwards
if filter_test_list:
ERP5TypeTestLoader.filter_test_list = old_filter_test_list
output = stream
if stream is None:
output = StringIO()
......
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