本文整理汇总了Python中unittest.TestLoader.getTestCaseNames方法的典型用法代码示例。如果您正苦于以下问题:Python TestLoader.getTestCaseNames方法的具体用法?Python TestLoader.getTestCaseNames怎么用?Python TestLoader.getTestCaseNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.TestLoader
的用法示例。
在下文中一共展示了TestLoader.getTestCaseNames方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_suite
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def build_suite(self, test_labels, extra_tests=None, **kwargs):
'''
Override the base class method to return a suite consisting of all
TestCase subclasses throughought the whole project.
'''
if test_labels:
suite = TestSuite()
else:
suite = DjangoTestSuiteRunner.build_suite(
self, test_labels, extra_tests, **kwargs
)
added_test_classes = set(t.__class__ for t in suite)
loader = TestLoader()
for fname in _get_module_names(os.getcwd()):
module = _import(_to_importable_name(fname))
for test_class in _get_testcases(module):
if test_class in added_test_classes:
continue
for method_name in loader.getTestCaseNames(test_class):
testname = '.'.join([
module.__name__, test_class.__name__, method_name
])
if self._test_matches(testname, test_labels):
suite.addTest(loader.loadTestsFromName(testname))
added_test_classes.add(test_class)
return reorder_suite(suite, (TestCase,))
示例2: collect
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def collect(self):
from unittest import TestLoader
cls = self.obj
if not getattr(cls, "__test__", True):
return
self.session._fixturemanager.parsefactories(self, unittest=True)
loader = TestLoader()
module = self.getparent(Module).obj
foundsomething = False
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
if not getattr(x, "__test__", True):
continue
funcobj = getattr(x, "im_func", x)
transfer_markers(funcobj, cls, module)
yield TestCaseFunction(name, parent=self, callobj=funcobj)
foundsomething = True
if not foundsomething:
runtest = getattr(self.obj, "runTest", None)
if runtest is not None:
ut = sys.modules.get("twisted.trial.unittest", None)
if ut is None or runtest != ut.TestCase.runTest:
yield TestCaseFunction("runTest", parent=self)
示例3: collect
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def collect(self):
from unittest import TestLoader
cls = self.obj
if not getattr(cls, "__test__", True):
return
skipped = getattr(cls, "__unittest_skip__", False)
if not skipped:
self._inject_setup_teardown_fixtures(cls)
self._inject_setup_class_fixture()
self.session._fixturemanager.parsefactories(self, unittest=True)
loader = TestLoader()
foundsomething = False
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
if not getattr(x, "__test__", True):
continue
funcobj = getimfunc(x)
yield TestCaseFunction(name, parent=self, callobj=funcobj)
foundsomething = True
if not foundsomething:
runtest = getattr(self.obj, "runTest", None)
if runtest is not None:
ut = sys.modules.get("twisted.trial.unittest", None)
if ut is None or runtest != ut.TestCase.runTest:
yield TestCaseFunction("runTest", parent=self)
示例4: parametrize
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def parametrize(testcase_class, users):
""" Create a suite containing all tests taken from the given
subclass, passing them the parameter 'client'.
"""
testloader = TestLoader()
testnames = testloader.getTestCaseNames(testcase_class)
tests = []
for name in testnames:
# Not logged in
client = Client()
tests.append(testcase_class(name, client=client))
# Log in users
for user in users:
client = Client()
tests.append(testcase_class(name, client=client, username=user['username'], password=user['password']))
return tests
示例5: find_tests_and_apps
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def find_tests_and_apps(self, label):
"""Construct a test suite of all test methods with the specified name.
Returns an instantiated test suite corresponding to the label provided.
"""
tests = []
from unittest import TestLoader
loader = TestLoader()
from django.db.models import get_app, get_apps
for app_models_module in get_apps():
app_name = app_models_module.__name__.rpartition(".")[0]
if app_name == label:
from django.test.simple import build_suite
tests.append(build_suite(app_models_module))
from django.test.simple import get_tests
app_tests_module = get_tests(app_models_module)
for sub_module in [m for m in app_models_module, app_tests_module if m is not None]:
# print "Checking for %s in %s" % (label, sub_module)
for name in dir(sub_module):
obj = getattr(sub_module, name)
import types
if isinstance(obj, (type, types.ClassType)) and issubclass(obj, unittest.TestCase):
test_names = loader.getTestCaseNames(obj)
# print "Checking for %s in %s.%s" % (label, obj, test_names)
if label in test_names:
tests.append(loader.loadTestsFromName(label, obj))
try:
module = sub_module
from django.test import _doctest as doctest
from django.test.testcases import DocTestRunner
doctests = doctest.DocTestSuite(module, checker=self.doctestOutputChecker, runner=DocTestRunner)
# Now iterate over the suite, looking for doctests whose name
# matches the pattern that was given
for test in doctests:
if test._dt_test.name in (
"%s.%s" % (module.__name__, ".".join(parts[1:])),
"%s.__test__.%s" % (module.__name__, ".".join(parts[1:])),
):
tests.append(test)
except TypeError as e:
raise Exception("%s appears not to be a module: %s" % (module, e))
except ValueError:
# No doctests found.
pass
# If no tests were found, then we were given a bad test label.
if not tests:
raise ValueError(("Test label '%s' does not refer to a " + "test method or app") % label)
# Construct a suite out of the tests that matched.
return unittest.TestSuite(tests)
示例6: initTest
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def initTest(klass, gn2_url, es_url):
loader = TestLoader()
methodNames = loader.getTestCaseNames(klass)
return [klass(mname, gn2_url, es_url) for mname in methodNames]
示例7: __import__
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
# Dynamically import test module
module = __import__(_UNIT_TEST_PKG.format(test_name))
test_module = getattr(module, test_name)
# Iterate over the list of attributes for test module to find valid
# TestCase objects.
for name in dir(test_module):
# Process object if subclass of TestCase.
obj = getattr(test_module, name)
if isinstance(obj, type) and issubclass(obj, TestCase):
# Check if object is subclass tests.utils.TestCase to pass
# required arguments.
use_args = True \
if issubclass(obj, unit_tests.utils.GadgetsTestCase) \
else False
# Get test names (methods).
testnames = testloader.getTestCaseNames(obj)
for testname in testnames:
if use_args:
# Add test with specific arguments.
test_instance = obj(testname, options=test_options)
suite.addTest(test_instance)
# Store max number of servers required by test.
num_servers = test_instance.num_servers_required
if num_servers > num_srv_needed:
num_srv_needed = num_servers
else:
# Add test without arguments (default).
suite.addTest(obj(testname))
except Exception as err: # pylint: disable=W0703
sys.stderr.write("ERROR: Could not load tests to run: {0}"
"\n".format(err))
示例8: __init__
# 需要导入模块: from unittest import TestLoader [as 别名]
# 或者: from unittest.TestLoader import getTestCaseNames [as 别名]
def __init__(self, test_case_class):
my_load = TestLoader()
self.methods = my_load.getTestCaseNames(test_case_class)