import os import os.path as path import importlib from glob import iglob __all__ = ['loadTestLists'] def loadPlugins(config): ''' Find and import all submodules in the current package's directory. Rather than making everyone enumerate all the types of tests, they can simply drop .py files in here. As long as they have a generateTestList() function, they'll be loaded and work. ''' plugins = {} suitesDir = path.dirname(path.realpath(__file__)) for pyfile in iglob(path.join(suitesDir, '[!_]*.py')): p = path.basename(pyfile)[:-3] plugin = importlib.import_module('suites.' + p) if plugin.init(config): plugins[p] = plugin return plugins def loadTestLists(config, desiredSuites = None): '''Generate the necessary test lists! desiredSuites may be None (to load all test suites). ''' suites = loadPlugins(config) tests = {} for suite, plugin in suites.items(): if not desiredSuites or suite in desiredSuites: tests.update(plugin.makeTestList()) return tests