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 ): ...@@ -1203,6 +1203,17 @@ def initialize( context ):
result = global_stream.read() result = global_stream.read()
return result 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') security.declareProtected(Permissions.ManagePortal, 'runLiveTest')
def runLiveTest(self, test_list=None, run_only=None, debug=False, def runLiveTest(self, test_list=None, run_only=None, debug=False,
verbose=False): verbose=False):
...@@ -1218,18 +1229,22 @@ def initialize( context ): ...@@ -1218,18 +1229,22 @@ def initialize( context ):
# Allow having strings for verbose and debug # Allow having strings for verbose and debug
verbose = int(verbose) and True or False verbose = int(verbose) and True or False
debug = int(debug) and True or False debug = int(debug) and True or False
if test_list is None: test_list = self._getCommaSeparatedParameterList(test_list)
test_list = [] run_only = self._getCommaSeparatedParameterList(run_only)
elif isinstance(test_list, str): if not test_list:
test_list = test_list.split(',') # no test to run
return ''
path = os.path.join(getConfiguration().instancehome, 'tests') path = os.path.join(getConfiguration().instancehome, 'tests')
verbosity = verbose and 2 or 1 verbosity = verbose and 2 or 1
instance_home = getConfiguration().instancehome
global global_stream global global_stream
global_stream = StringIO() global_stream = StringIO()
from Products.ERP5Type.tests.ERP5TypeLiveTestCase import runLiveTest from Products.ERP5Type.tests.ERP5TypeLiveTestCase import runLiveTest
result = runLiveTest(test_list, run_only=run_only, debug=debug, path=path, result = runLiveTest(test_list,
stream=global_stream, verbosity=verbosity) run_only=run_only,
debug=debug,
path=path,
stream=global_stream,
verbosity=verbosity)
global_stream.seek(0) global_stream.seek(0)
return global_stream.read() return global_stream.read()
......
...@@ -138,6 +138,20 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader): ...@@ -138,6 +138,20 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader):
# do not filter if no filter, otherwise no tests run # do not filter if no filter, otherwise no tests run
self.filter_test_list = filter_test_list 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): def loadTestsFromModule(self, module):
"""ERP5Type test re-loader supports reloading test modules before """ERP5Type test re-loader supports reloading test modules before
running them. running them.
...@@ -145,6 +159,11 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader): ...@@ -145,6 +159,11 @@ class ERP5TypeTestReLoader(ERP5TypeTestLoader):
reload(module) reload(module)
return super(ERP5TypeTestReLoader, self).loadTestsFromModule(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): def runLiveTest(test_list, verbosity=1, stream=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult from Products.ERP5Type.tests.runUnitTest import DebugTestResult
from Products.ERP5Type.tests import backportUnittest from Products.ERP5Type.tests import backportUnittest
...@@ -171,19 +190,11 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw): ...@@ -171,19 +190,11 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
result = super(DebugTextTestRunner, self)._makeResult() result = super(DebugTextTestRunner, self)._makeResult()
return DebugTestResult(result) return DebugTestResult(result)
TestRunner = DebugTextTestRunner TestRunner = DebugTextTestRunner
run_only = kw.get('run_only', '').strip() run_only = kw.get('run_only', ())
filter_test_list = [re.compile(x.strip()).search filter_test_list = [re.compile(x).search
for x in run_only.split(',')] for x in run_only]
loader = ERP5TypeTestReLoader() loader = ERP5TypeTestReLoader(filter_test_list)
# 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
suite = loader.loadTestsFromNames(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 output = stream
if stream is None: if stream is None:
output = StringIO() 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