configurationengine/source/cone/public/tests/__init__.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    11 #
    11 #
    12 # Contributors:
    12 # Contributors:
    13 #
    13 #
    14 # Description: 
    14 # Description: 
    15 #
    15 #
    16 
       
    17 import unittest, os, sys
       
    18 
       
    19 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    20 SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..'))
       
    21 if SOURCE_ROOT not in sys.path:
       
    22     sys.path.append(SOURCE_ROOT)
       
    23 
       
    24 # Find all unittest_*.py files in this folder
       
    25 import re
       
    26 __all__ = filter(lambda name: re.match(r'^unittest_.*\.py$', name) != None, os.listdir(ROOT_PATH))
       
    27 # Strip .py endings
       
    28 __all__ = map(lambda name: name[:-3], __all__)
       
    29 
       
    30 def collect_suite():  
       
    31     sys.path.insert(0, ROOT_PATH)
       
    32     try:
       
    33         suite = unittest.TestSuite()
       
    34         for test_module in __all__:
       
    35             # Load the test module dynamically and add it to the test suite
       
    36             module = __import__(test_module)
       
    37             suite.addTests(unittest.TestLoader().loadTestsFromModule(module))
       
    38         return suite
       
    39     finally:
       
    40         del sys.path[0]
       
    41 
       
    42 def runtests():
       
    43     unittest.TextTestRunner(verbosity=2).run(collect_suite())
       
    44 
       
    45 if __name__ == '__main__':
       
    46     runtests()