本文整理汇总了Python中django.utils.unittest.TestCase方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.TestCase方法的具体用法?Python unittest.TestCase怎么用?Python unittest.TestCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.unittest
的用法示例。
在下文中一共展示了unittest.TestCase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_suite
# 需要导入模块: from django.utils import unittest [as 别名]
# 或者: from django.utils.unittest import TestCase [as 别名]
def build_suite(self, test_labels, extra_tests=None, **kwargs):
suite = unittest.TestSuite()
if test_labels:
for label in test_labels:
if '.' in label:
suite.addTest(build_test(label))
else:
app = get_app(label)
suite.addTest(build_suite(app))
else:
for app in get_apps():
suite.addTest(build_suite(app))
if extra_tests:
for test in extra_tests:
suite.addTest(test)
return reorder_suite(suite, (unittest.TestCase,))
示例2: _fixture_setup
# 需要导入模块: from django.utils import unittest [as 别名]
# 或者: from django.utils.unittest import TestCase [as 别名]
def _fixture_setup(self):
if not connections_support_transactions():
return super(TestCase, self)._fixture_setup()
assert not self.reset_sequences, 'reset_sequences cannot be used on TestCase instances'
for db_name in self._databases_names():
transaction.enter_transaction_management(using=db_name)
transaction.managed(True, using=db_name)
disable_transaction_methods()
from django.contrib.sites.models import Site
Site.objects.clear_cache()
for db in self._databases_names(include_mirrors=False):
if hasattr(self, 'fixtures'):
call_command('loaddata', *self.fixtures,
**{
'verbosity': 0,
'commit': False,
'database': db,
'skip_validation': True,
})
示例3: _fixture_teardown
# 需要导入模块: from django.utils import unittest [as 别名]
# 或者: from django.utils.unittest import TestCase [as 别名]
def _fixture_teardown(self):
if not connections_support_transactions():
return super(TestCase, self)._fixture_teardown()
restore_transaction_methods()
for db in self._databases_names():
transaction.rollback(using=db)
transaction.leave_transaction_management(using=db)
示例4: _deferredSkip
# 需要导入模块: from django.utils import unittest [as 别名]
# 或者: from django.utils.unittest import TestCase [as 别名]
def _deferredSkip(condition, reason):
def decorator(test_func):
if not (isinstance(test_func, type) and
issubclass(test_func, TestCase)):
@wraps(test_func)
def skip_wrapper(*args, **kwargs):
if condition():
raise ut2.SkipTest(reason)
return test_func(*args, **kwargs)
test_item = skip_wrapper
else:
test_item = test_func
test_item.__unittest_skip_why__ = reason
return test_item
return decorator