Dynamic Test Loading

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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))

More like this

  1. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  2. Complex Formsets by smagala 4 years, 4 months ago
  3. db_dump.py - for dumpping and loading data from database by limodou 6 years, 2 months ago
  4. Deep package test runner by eternicode 2 years, 2 months ago
  5. Log all interaction with user to the DB by inuwashi 2 years, 4 months ago

Comments

(Forgotten your password?)