3
from __future__ import print_function
9
from tests import colors
11
# TODO: Read a file to parse some configuration and read which directory to browse
12
path_for_tests = 'tests'
19
Launch all 'test_' files in a specific directory
22
suite = unittest.TestSuite() # the suite of tests
23
test_modules = [] # modules that are in 'tests' directory
24
added_paths = [] # path added to PYTHONPATH
25
c = colors.TerminalColors()
28
# Browse the directory to search all tests
29
print (c.BGreen + 'Browsing' + c.Color_Off + ' %s directory.' % path_for_tests)
30
for racine, _, files in walk(path_for_tests):
31
directory = path.basename(racine)
32
if directory == 'tests':
34
if (f.startswith('test') and f.endswith('.py') and f != 'test.py'):
35
name = path.join(racine, f)
36
test_modules.append((name, f[:-3]))
37
# Inform how many modules was found
38
print ('%d module(s) found' % len(test_modules))
41
# # Launch a python script that runs some tasks before tests
42
# print ('Launch pre-tasks')
43
# execfile('pre_runner.py')
46
# Import found modules
47
print(c.BGreen + 'Import' + c.Color_Off + ' modules + instanciate them')
48
#+ Sort them by module name (x[1])
49
for module_info in sorted(test_modules, key=lambda x: x[1]):
50
module_path = path.dirname(module_info[0])
51
if module_path not in sys.path:
52
sys.path.append(module_path)
53
added_paths.append(module_path)
55
module = __import__(module_info[1])
56
if 'get_test_class' in module.__dict__:
57
class_type = module.get_test_class()
58
print ("%s module:" % (class_type.__module__,))
59
test_suite = unittest.TestSuite((unittest.makeSuite(class_type), ))
60
suite.addTest(test_suite)
63
# Create a file for the output result
64
output = file('output.html', 'wb')
66
campaign = HTMLTestRunner.HTMLTestRunner(
68
title='Example tests',
69
description='A suite of tests that permit to test PyUnit class'
71
print('Launch UnifieldTest ' + c.BGreen + 'Campaign' + c.Color_Off)
72
print('----------------------------\n')
73
print('Note: 1 point represents a test. F means Fail. E means Error.')
77
print ('Clean used paths')
78
# Delete all paths added to the PYTHONPATH
79
for added_path in added_paths:
80
sys.path.remove(added_path)
83
# # Launch a python script that runs some tasks after all tests
84
# print ('Launch post-tasks')
85
# execfile('post_runner.py')
89
if __name__ == "__main__":
92
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'