25 def _setup(): |
25 def _setup(): |
26 """ |
26 """ |
27 Set up everything so that running "python cone_tool.py" finds the ConE |
27 Set up everything so that running "python cone_tool.py" finds the ConE |
28 and plug-in modules. |
28 and plug-in modules. |
29 """ |
29 """ |
30 sys.path.append(SOURCE_ROOT) |
30 from testautomation import plugin_utils |
31 sys.path.append(os.path.join(SOURCE_ROOT, 'testautomation')) |
|
32 |
|
33 # Import the plugin_utils module from plugins/ |
|
34 sys.path.append(PLUGIN_SOURCE_ROOT) |
|
35 import plugin_utils |
|
36 del sys.path[-1] |
|
37 |
31 |
38 # Collect all needed plug-in source directories (all in 'common') |
32 # Collect all needed plug-in source directories (all in 'common') |
39 plugin_sources = plugin_utils.find_plugin_sources(os.path.join(PLUGIN_SOURCE_ROOT, 'common')) |
33 plugin_sources = plugin_utils.find_plugin_sources(os.path.join(PLUGIN_SOURCE_ROOT, 'common')) |
40 plugin_source_paths = [path for path, _ in plugin_sources] |
34 plugin_source_paths = [path for path, _ in plugin_sources] |
41 |
35 |
42 paths = [] |
|
43 paths.append(SOURCE_ROOT) |
|
44 paths.extend(plugin_source_paths) |
|
45 os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ';' + ';'.join(paths) |
|
46 |
|
47 # Generate egg-info for the plug-ins if necessary |
36 # Generate egg-info for the plug-ins if necessary |
48 import build_egg_info |
37 from testautomation import build_egg_info |
49 for path in plugin_source_paths: |
38 for path in plugin_source_paths: |
50 build_egg_info.generate_egg_info(path) |
39 build_egg_info.generate_egg_info(path) |
51 |
40 |
52 _setup() |
41 _setup() |
53 |
42 |
54 # Find all unittest_*.py files in this folder |
|
55 import re |
|
56 __all__ = filter(lambda name: re.match(r'^unittest_.*\.py$', name) != None, os.listdir(ROOT_PATH)) |
|
57 # Strip .py endings |
|
58 __all__ = map(lambda name: name[:-3], __all__) |
|
59 |
|
60 def collect_suite(): |
|
61 suite = unittest.TestSuite() |
|
62 for test_module in __all__: |
|
63 # Load the test module dynamically and add it to the test suite |
|
64 module = __import__(test_module) |
|
65 suite.addTests(unittest.TestLoader().loadTestsFromModule(module)) |
|
66 return suite |
|
67 |
|
68 def runtests(): |
|
69 unittest.TextTestRunner(verbosity=2).run(collect_suite()) |
|
70 |
|
71 if __name__ == '__main__': |
|
72 runtests() |
|