diff --git a/product/ERP5Type/Tool/ClassTool.py b/product/ERP5Type/Tool/ClassTool.py index 7d234eba6a44de99bea374e5c54b46383df4f3c0..120ddfc4a0fb56af96122f1e2770c84a5772930e 100644 --- a/product/ERP5Type/Tool/ClassTool.py +++ b/product/ERP5Type/Tool/ClassTool.py @@ -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): diff --git a/product/ERP5Type/tests/ERP5TypeLiveTestCase.py b/product/ERP5Type/tests/ERP5TypeLiveTestCase.py index c12a2372bc9e3c47dc2ee8dc1a3650903d9d2750..5b325b708a965abc1c64b345f6d424e54b7811f6 100644 --- a/product/ERP5Type/tests/ERP5TypeLiveTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeLiveTestCase.py @@ -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")