import os import glob import unittest import django test import inspec

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import os
import glob
import unittest
import django.test
import inspect
def theimport(module_path):
fr = inspect.stack()[1][0]
file_full_path = os.path.abspath(os.path.join(module_path, '..'))
app_name = file_full_path.split("/")[-2]
for filename in glob.glob(file_full_path + "/[a-z]*.py"):
module_name = os.path.basename(filename).split(".py")[0]
full_module_name = "%s.tests.%s" % (app_name, module_name)
m = __import__(full_module_name, {}, {}, [module_name])
mdir = dir(m)
for name in mdir:
attr = getattr(m, name)
if type(attr) is type:
if issubclass(attr, unittest.TestCase) or issubclass(attr, django.test.TestCase):
fr.f_globals[name] = attr