Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用unittest动态加载测试_Python_Python Unittest - Fatal编程技术网

Python 如何使用unittest动态加载测试

Python 如何使用unittest动态加载测试,python,python-unittest,Python,Python Unittest,我还没有长大到使用测试框架的地步。但有时我想检查所有的测试。当我进行测试时,我只使用一个。帮助我动态加载模块/测试。我想我错过了一些东西 import sys import importlib import settings settings.TESTING = True settings.SQLALCHEMY_DATABASE_URI = 'sqlite:///test.sqlite' from application import app import unittest argv = s

我还没有长大到使用测试框架的地步。但有时我想检查所有的测试。当我进行测试时,我只使用一个。帮助我动态加载模块/测试。我想我错过了一些东西

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() 

我想我应该更好地阅读文档。标准功能就足够了。你考虑过使用单元测试框架吗?