Commit a582e433 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update tests runner to report failed imports and include new functional tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1188 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent cbf9305e
...@@ -56,10 +56,14 @@ UNIT_TEST_MODULES = [ ...@@ -56,10 +56,14 @@ UNIT_TEST_MODULES = [
] ]
FUNC_TEST_MODULES = [ FUNC_TEST_MODULES = [
'neo.tests.functional.testZODB', ('neo.tests.functional.testZODB', 'check'),
'neo.tests.functional.testMaster',
'neo.tests.functional.testStorage',
'neo.tests.functional.testImportExport',
] ]
# configuration # configuration
UNIT_TESTS = True
FUNCTIONAL_TESTS = True FUNCTIONAL_TESTS = True
SEND_REPORT = False SEND_REPORT = False
CONSOLE_LOG = False CONSOLE_LOG = False
...@@ -89,17 +93,24 @@ class NeoTestRunner(unittest.TestResult): ...@@ -89,17 +93,24 @@ class NeoTestRunner(unittest.TestResult):
def __init__(self): def __init__(self):
unittest.TestResult.__init__(self) unittest.TestResult.__init__(self)
self.modulesStats = {} self.modulesStats = {}
self.failedImports = {}
self.lastStart = None self.lastStart = None
def run(self, name, modules, prefix='test'): def run(self, name, modules):
suite = unittest.TestSuite() suite = unittest.TestSuite()
loader = unittest.defaultTestLoader loader = unittest.defaultTestLoader
loader.testMethodPrefix = prefix
for test_module in modules: for test_module in modules:
# load prefix if supplied
if isinstance(test_module, tuple):
test_module, prefix = test_module
loader.testMethodPrefix = prefix
else:
loader.testMethodPrefix = 'test'
try: try:
test_module = __import__(test_module, globals(), locals(), ['*']) test_module = __import__(test_module, globals(), locals(), ['*'])
except ImportError, err: except ImportError, err:
# TODO: include import errors in report # TODO: include import errors in report
self.failedImports[test_module] = err
print "Import of %s failed : %s" % (test_module, err) print "Import of %s failed : %s" % (test_module, err)
continue continue
suite.addTests(loader.loadTestsFromModule(test_module)) suite.addTests(loader.loadTestsFromModule(test_module))
...@@ -227,12 +238,22 @@ class NeoTestRunner(unittest.TestResult): ...@@ -227,12 +238,22 @@ class NeoTestRunner(unittest.TestResult):
s += '\n' s += '\n'
return s return s
def _buildWarnings(self):
s = '\n'
if self.failedImports:
s += 'Failed imports :\n'
for module, err in self.failedImports.items():
s += '%s:\n%s' % (module, err)
s += '\n'
return s
def build(self): def build(self):
self.time = sum([s.time for s in self.modulesStats.values()]) self.time = sum([s.time for s in self.modulesStats.values()])
args = (self.testsRun, len(self.errors), len(self.failures)) args = (self.testsRun, len(self.errors), len(self.failures))
self.subject = "Neo : %s Tests, %s Errors, %s Failures" % args self.subject = "Neo : %s Tests, %s Errors, %s Failures" % args
self.summary = self._buildSummary() self.summary = self._buildSummary()
self.errors = self._buildErrors() self.errors = self._buildErrors()
self.warnings = self._buildWarnings()
def sendReport(self): def sendReport(self):
""" Send a mail with the report summary """ """ Send a mail with the report summary """
...@@ -274,14 +295,19 @@ class NeoTestRunner(unittest.TestResult): ...@@ -274,14 +295,19 @@ class NeoTestRunner(unittest.TestResult):
if __name__ == "__main__": if __name__ == "__main__":
if not UNIT_TESTS and not FUNCTIONAL_TESTS:
raise RuntimeError('Nothing to run')
# run and build the report # run and build the report
runner = NeoTestRunner() runner = NeoTestRunner()
if UNIT_TESTS:
runner.run('Unit tests', UNIT_TEST_MODULES) runner.run('Unit tests', UNIT_TEST_MODULES)
if FUNCTIONAL_TESTS: if FUNCTIONAL_TESTS:
runner.run('Functional tests', FUNC_TEST_MODULES, prefix='check') runner.run('Functional tests', FUNC_TEST_MODULES)
runner.build() runner.build()
# send a mail # send a mail
if SEND_REPORT: if SEND_REPORT:
runner.sendReport() runner.sendReport()
print runner.errors print runner.errors
print runner.warnings
print runner.summary print runner.summary
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