Commit 7a7060b2 authored by Sebastien Robin's avatar Sebastien Robin

* add method runLiveTest in portal_classes

* add some features of runUnitTest in runLiveTest :
  - run_only option
  - debug option

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38051 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 089ec50d
......@@ -1178,6 +1178,19 @@ def initialize( context ):
writeLocalConstraint(class_id, text, create=create,
instance_home=self._v_instance_home.getPath())
security.declareProtected(Permissions.ManagePortal, 'runLiveTest')
def runLiveTest(self, test_list=[], run_only=None, debug=None):
"""
Launch live tests
run_only=STRING Run only specified test methods delimited with
commas (e.g. testFoo,testBar). This can be regular
expressions.
debug=boolean Invoke debugger on errors / failures.
"""
path = os.path.join(getConfiguration().instancehome, 'tests')
return runLiveTest(test_list, run_only=run_only, debug=debug, path=path)
else:
class ClassTool(BaseTool, ClassToolMixIn):
......
......@@ -88,6 +88,8 @@ class ERP5TypeLiveTestCase(ProcessingNodeTestCase, PortalTestCase):
"""
# Assumes that portal exists (which has sense) and that there is only one
# ERP5 site in Zope (which is always the case)
if self.app.meta_type == 'ERP5 Site':
return self.app
return [q for q in self.app.objectValues() if q.meta_type == 'ERP5 Site'
][0]
......@@ -435,12 +437,34 @@ class ERP5TypeLiveTestCase(ProcessingNodeTestCase, PortalTestCase):
return ResponseWrapper(response, outstream, path)
def runLiveTest(self, suite):
def runLiveTest(test_list, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult
from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader
from Products.ERP5Type.tests import backportUnittest
from StringIO import StringIO
import imp
import re
# Add path of the TestTemplateItem folder of the instance
path = kw.get('path', None)
if path is not None and path not in sys.path:
sys.path.append(path)
# Reload the test class before runing tests
for test_name in test_list:
(test_file, test_path_name, test_description) = imp.find_module(test_name)
imp.load_module(test_name, test_file, test_path_name, test_description)
TestRunner = backportUnittest.TextTestRunner
unittest.TestLoader = ERP5TypeTestLoader
if kw.get('debug', False):
class DebugTextTestRunner(TestRunner):
def _makeResult(self):
result = super(DebugTextTestRunner, self)._makeResult()
return DebugTestResult(result)
TestRunner = DebugTextTestRunner
run_only = kw.get('run_only', None)
if run_only is not None:
ERP5TypeTestLoader.filter_test_list = [re.compile(x).search
for x in run_only.split(',')]
suite = ERP5TypeTestLoader().loadTestsFromNames(test_list)
stream = StringIO()
output = StringIO()
output.write("**Running Live Test:\n")
......
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