# testhelper.py def get_sub_modules(f, ignore = [], base = None): import os modules = [] top = os.path.split(f)[0] for root, dirs, files in os.walk(top, topdown=False): for name in files: if '.svn' in root: continue if not name.endswith('.py'): continue pkg = root.replace(top, '') if pkg.startswith(os.sep): pkg = pkg[1:] pkg = pkg.replace('/', '.').replace('\\', '.') module = os.path.splitext(name)[0] if name.startswith('__') or name in ignore or module in ignore: continue path = '.'.join([pkg, module]) if len(pkg.strip()) == 0: path = module if base is not None: path = '.'.join([base, path]) modules.append(path) return modules # app.tests.__init__.py import testhelper modules = testhelper.get_sub_modules(__file__, base='time_punch.tests') for m in modules: exec('from %s import *' %(m))