Djangoは <app>/tests.py(models.py) しか実行してくれないので、任意のモジュールのTestCaseをglobalにimportして実行させる。
import imp, unittest
def get_tests(module):
result = dict()
f, fn, desc = imp.find_module("tests", module.__path__)
_module = imp.load_module("tests", f, fn, desc)
for key, value in _module.__dict__.items():
if type(value) is type and issubclass(value, unittest.TestCase):
result[key] = value
return result
from contrib import webdesign
globals().update(get_tests(webdesign))
とかすると、 somewhere/contrib/webdesign/tests.py のTestCaseをimportした<app>で実行できる。 utils系のモジュールを階層化して管理したい時などに便利。
