我还没有成长为使用测试框架。但有时我想检查所有测试。当我进行测试时,我只使用一个。帮我动态加载模块/测试。我想我已经错过了一些东西。
import sys
import importlib
import settings
settings.TESTING = True
settings.SQLALCHEMY_DATABASE_URI = 'sqlite:///test.sqlite'
from application import app
import unittest
argv = sys.argv[1:]
ALL = argv[0] == 'ALL'
tests = dict(
RestAuthTestCase=('ext.core.test.lib.rest_auth', 'RestAuthTestCase'),
UserModelTestCase=('ext.user.test.user_model', 'UserModelTestCase'),
BudgetModelTestCase=('ext.budget.test.budget_model', 'BudgetModelTestCase'),
TagModelTestCase=('ext.budget.test.tag_model', 'TagModelTestCase'),
ExpenseModelTestCase=('ext.budget.test.expense_model', 'ExpenseModelTestCase'),
TableTestCase=('ext.budget.test.table', 'TableTestCase'),
UserRestTestCase=('ext.user.test.rest', 'UserRestTestCase')
)
for test_key in argv:
test_pkg, test_name = tests[test_key]
mod = __import__(test_pkg, globals(), locals(), fromlist=[test_name])
klass = getattr(mod, test_name)
if __name__ == '__main__':
unittest.main()