Commit f629a8db authored by Sebastien Robin's avatar Sebastien Robin

Revert "ERP5TypeLiveTestCase: Remove FS reloader as ZODB Components should be used from now on."

This code is useful to run any unit test in a live instance. Until all products tests (like
ERP5/tests/*) are moved as components, this code is useful.

This reverts commit 9240d498.
parent 2c046332
......@@ -166,10 +166,31 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
from Products.ERP5Type.dynamic.component_package import ComponentDynamicPackage
from Products.ERP5Type.tests.runUnitTest import ERP5TypeTestLoader
class ERP5TypeLiveTestLoader(ERP5TypeTestLoader):
"""
ERP5Type Live Test loader which allows to load ZODB Components if any
class ERP5TypeTestReLoader(ERP5TypeTestLoader):
"""ERP5Type test re-loader supports reloading test modules before
running them.
"""
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 loadTestsFromName(self, name, module=None):
"""
Load the test from the given name from ZODB if it can be imported,
......@@ -183,12 +204,33 @@ class ERP5TypeLiveTestLoader(ERP5TypeTestLoader):
fromlist=['erp5.component.test'],
level=0)
except ImportError:
raise
pass
else:
module = erp5.component.test
return super(ERP5TypeLiveTestLoader, self).loadTestsFromName(name,
module)
return super(ERP5TypeTestReLoader, self).loadTestsFromName(name,
module)
def loadTestsFromModule(self, module):
"""
If the module is not a ZODB Component, then reload it to consider
modifications on the filesystem
"""
if not isinstance(getattr(module, '__loader__', None),
ComponentDynamicPackage):
reload(module)
return super(ERP5TypeTestReLoader, self).loadTestsFromModule(module)
def loadTestsFromTestCase(self, testCaseClass):
testModule = sys.modules[testCaseClass.__module__]
# Do not reload ERP5TypeTestCase because we patch it nor ZODB Test
# Component as it is reset upon modification anyway
if (testCaseClass is not ERP5TypeTestCase and
not isinstance(getattr(testModule, '__loader__', None),
ComponentDynamicPackage)):
testModule = reload(testModule)
testCaseClass = getattr(testModule, testCaseClass.__name__)
return ERP5TypeTestLoader.loadTestsFromTestCase(self, testCaseClass)
def runLiveTest(test_list, verbosity=1, stream=None, request_server_url=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult
......@@ -221,9 +263,7 @@ def runLiveTest(test_list, verbosity=1, stream=None, request_server_url=None, **
run_only = kw.get('run_only', ())
filter_test_list = [re.compile(x).search
for x in run_only]
loader = ERP5TypeLiveTestLoader()
ERP5TypeTestLoader.filter_test_list = filter_test_list
loader = ERP5TypeTestReLoader(filter_test_list)
suite = loader.loadTestsFromNames(test_list)
output = stream
if stream is None:
......
......@@ -625,9 +625,12 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None):
TestRunner = DebugTextTestRunner
loader = ERP5TypeTestLoader()
if run_only:
ERP5TypeTestLoader.filter_test_list = [re.compile(x).search
for x in run_only.split(',')]
ERP5TypeTestLoader.filter_test_list = [re.compile(x).search for x in
run_only.split(',')]
suite = loader.loadTestsFromNames(test_list)
if run_only:
ERP5TypeTestLoader.filter_test_list = None
if node_pid_list is None:
result = suite()
......
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