17 Creates a Test Suite from all the tests inside a python package which is located in the MeVisLab Repository.
19 Example usage inside a MeVisLab TestCenter Test:
21 from TestSupport.UnitTestDiscovery import getSuiteFromPackage
22 import my_module.core.tests
25 def UNITTEST_My_Module():
26 return getSuiteFromPackage(my_module.core.tests)
28 :param unitTestRootPackage: the python package in which unit tests are searched
29 :type unitTestRootPackage: ModuleType
30 :param pattern: Only test files that match the pattern will be loaded.
32 More details can be found in the documentation of the TestLoader.discover() function.
34 searchPath = unitTestRootPackage.__path__[0]
35 top_level_dir = _getTopLevelDir(searchPath)
38 return unittest.TestLoader().discover(searchPath, pattern, top_level_dir=top_level_dir)
41 def _getTopLevelDir(searchPath):
42 pythonFolder = os.path.join(
"Scripts",
"python")
43 top_level_dir = searchPath[0:searchPath.find(pythonFolder) + len(pythonFolder)]
49 Creates a Test Suite from all the tests inside a folder, this could be a TestCenter TestCase folder.
50 :param searchPath: the folder where to search for the unit tests.
51 :param pattern: Only test files that match the pattern will be loaded.
53 return unittest.TestLoader().discover(searchPath, pattern)
def getSuiteFromPackage(unitTestRootPackage, pattern='test *.py')
def getSuiteFromFolder(searchPath, pattern=' *.py')