Commit e3f2be25 authored by Jérome Perrin's avatar Jérome Perrin

Test: Repair --run_only

Amend 9240d498: Since many Loaders are
instanciated by unittest itself, filter_test_list still have to be a class
variable
parent 735f8eaf
...@@ -214,7 +214,9 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw): ...@@ -214,7 +214,9 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
run_only = kw.get('run_only', ()) run_only = kw.get('run_only', ())
filter_test_list = [re.compile(x).search filter_test_list = [re.compile(x).search
for x in run_only] for x in run_only]
loader = ERP5TypeLiveTestLoader(filter_test_list) loader = ERP5TypeLiveTestLoader()
ERP5TypeTestLoader.filter_test_list = filter_test_list
suite = loader.loadTestsFromNames(test_list) suite = loader.loadTestsFromNames(test_list)
output = stream output = stream
if stream is None: if stream is None:
......
...@@ -268,16 +268,13 @@ else: ...@@ -268,16 +268,13 @@ else:
class ERP5TypeTestLoader(unittest.TestLoader): class ERP5TypeTestLoader(unittest.TestLoader):
"""Load test cases from the name passed on the command line. """Load test cases from the name passed on the command line.
""" """
filter_test_list = None
_testMethodPrefix = 'test' _testMethodPrefix = 'test'
testMethodPrefix = property( testMethodPrefix = property(
lambda self: self._testMethodPrefix, lambda self: self._testMethodPrefix,
lambda self, value: None) lambda self, value: None)
def __init__(self, filter_test_list=()):
super(ERP5TypeTestLoader, self).__init__()
self.filter_test_list = filter_test_list
def loadTestsFromName(self, name, module=None): def loadTestsFromName(self, name, module=None):
""" """
This method is here for compatibility with old style arguments: This method is here for compatibility with old style arguments:
...@@ -433,10 +430,10 @@ class ERP5TypeTestLoader(unittest.TestLoader): ...@@ -433,10 +430,10 @@ class ERP5TypeTestLoader(unittest.TestLoader):
The returned list only contain names matching --run_only The returned list only contain names matching --run_only
""" """
name_list = super(ERP5TypeTestLoader, self).getTestCaseNames(testCaseClass) name_list = super(ERP5TypeTestLoader, self).getTestCaseNames(testCaseClass)
if self.filter_test_list: if ERP5TypeTestLoader.filter_test_list:
filtered_name_list = [] filtered_name_list = []
for name in name_list: for name in name_list:
for test in self.filter_test_list: for test in ERP5TypeTestLoader.filter_test_list:
if test(name): if test(name):
filtered_name_list.append(name) filtered_name_list.append(name)
break break
...@@ -654,8 +651,10 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None): ...@@ -654,8 +651,10 @@ def runUnitTestList(test_list, verbosity=1, debug=0, run_only=None):
result = super(DebugTextTestRunner, self)._makeResult() result = super(DebugTextTestRunner, self)._makeResult()
return DebugTestResult(result) return DebugTestResult(result)
TestRunner = DebugTextTestRunner TestRunner = DebugTextTestRunner
loader = ERP5TypeTestLoader( loader = ERP5TypeTestLoader()
[re.compile(x).search for x in run_only.split(',')] if run_only else ()) if run_only:
ERP5TypeTestLoader.filter_test_list = [re.compile(x).search
for x in run_only.split(',')]
suite = loader.loadTestsFromNames(test_list) suite = loader.loadTestsFromNames(test_list)
if node_pid_list is None: if node_pid_list is None:
......
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