本文整理汇总了Python中testtools.iterate_tests函数的典型用法代码示例。如果您正苦于以下问题:Python iterate_tests函数的具体用法?Python iterate_tests怎么用?Python iterate_tests使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iterate_tests函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_tests_input_scenario_utils
def load_tests_input_scenario_utils(*args):
"""
Wrapper for testscenarios to set the scenarios to avoid running a getattr
on the CONF object at import.
"""
if getattr(args[0], "suiteClass", None) is not None:
loader, standard_tests, pattern = args
else:
standard_tests, module, loader = args
output = None
scenario_utils = None
try:
scenario_utils = InputScenarioUtils()
scenario_flavor = scenario_utils.scenario_flavors
scenario_image = scenario_utils.scenario_images
except (exc_lib.InvalidCredentials, TypeError):
output = standard_tests
finally:
if scenario_utils:
scenario_utils.clear_creds()
if output is not None:
return output
for test in testtools.iterate_tests(standard_tests):
setattr(test, "scenarios", testscenarios.multiply_scenarios(scenario_image, scenario_flavor))
return testscenarios.load_tests_apply_scenarios(*args)
示例2: test_load_tests
def test_load_tests(self):
tests.write_tree_from_desc('''dir: t
file: t/__init__.py
import unittest
def load_tests(test_loader, tests, ignore):
# A simple way to reveal the side effect is to add more tests
class TestLoadTest(unittest.TestCase):
def test_in_load_test(self):
self.assertTrue(True)
tests.addTests(test_loader.loadTestsFromTestCase(TestLoadTest))
return tests
class TestInit(unittest.TestCase):
def test_in_init(self):
self.assertTrue(True)
file: t/test_not_discovered.py
import unittest
class Test(unittest.TestCase):
def test_me(self):
self.assertTrue(True)
''')
test_loader = self.make_test_loader()
suite = test_loader.discoverTestsFromTree('t')
self.assertEqual(2, suite.countTestCases())
self.assertEqual(['t.TestInit.test_in_init',
't.TestLoadTest.test_in_load_test'],
[t.id() for t in testtools.iterate_tests(suite)])
示例3: test_regular_below_scripts
def test_regular_below_scripts(self):
tests.write_tree_from_desc('''dir: t
file: t/__init__.py
dir: t/regular
file: t/regular/__init__.py
from sst import loaders
discover = loaders.discoverRegularTests
file: t/regular/test_foo.py
import unittest
class Test(unittest.TestCase):
def test_me(self):
self.assertTrue(True)
file: t/script.py
raise AssertionError('Loading only, executing fails')
''')
suite = self.discover('t')
# Check which kind of tests have been discovered or we may miss regular
# test cases seen as scripts.
self.assertEqual(['t.regular.test_foo.Test.test_me',
't.script'],
[t.id() for t in testtools.iterate_tests(suite)])
示例4: partition_tests
def partition_tests(suite, count):
# Keep the same interface as the original concurrencytest.partition_tests
independent_old_modules = [
"pcs_test.tier0.test_constraints",
"pcs_test.tier0.test_resource",
"pcs_test.tier0.test_stonith",
]
old_tests = [] # tests are not independent, cannot run in parallel
old_tests_independent = {} # independent modules
independent_tests = []
for test in iterate_tests(suite):
module = test.__class__.__module__
if not (
module.startswith("pcs_test.tier0.test_")
or
module.startswith("pcs_test.tier0.cib_resource")
):
independent_tests.append(test)
elif module in independent_old_modules:
if module not in old_tests_independent:
old_tests_independent[module] = []
old_tests_independent[module].append(test)
else:
old_tests.append(test)
return [old_tests, independent_tests] + list(old_tests_independent.values())
示例5: test_scripts_below_regular
def test_scripts_below_regular(self):
tests.write_tree_from_desc('''dir: t
file: t/__init__.py
file: t/foo.py
import unittest
class Test(unittest.TestCase):
def test_me(self):
self.assertTrue(True)
dir: t/scripts
file: t/scripts/__init__.py
from sst import loader
discover = loader.discoverTestScripts
file: t/scripts/script.py
raise AssertionError('Loading only, executing fails')
''')
test_loader = loader.TestLoader()
suite = test_loader.discoverTests('t')
self.assertEqual(2, suite.countTestCases())
# Check which kind of tests have been discovered or we may miss regular
# test cases seen as scripts.
self.assertEqual(['t.foo.Test.test_me',
't.scripts.script'],
[t.id() for t in testtools.iterate_tests(suite)])
示例6: _iter_tests
def _iter_tests(names):
"""
Given a list of names, iterate through all the tests in them.
"""
for name in names:
suite = _load_tests(name)
for test in iterate_tests(suite):
yield test
示例7: test_custom_suite_without_sort_tests_works
def test_custom_suite_without_sort_tests_works(self):
a = PlaceHolder('a')
b = PlaceHolder('b')
class Subclass(unittest.TestSuite):pass
input_suite = Subclass([b, a])
suite = sorted_tests(input_suite)
self.assertEqual([b, a], list(iterate_tests(suite)))
self.assertEqual([input_suite], list(iter(suite)))
示例8: test_sorts_custom_suites
def test_sorts_custom_suites(self):
a = PlaceHolder('a')
b = PlaceHolder('b')
class Subclass(unittest.TestSuite):
def sort_tests(self):
self._tests = sorted_tests(self, True)
input_suite = Subclass([b, a])
suite = sorted_tests(input_suite)
self.assertEqual([a, b], list(iterate_tests(suite)))
self.assertEqual([input_suite], list(iter(suite)))
示例9: test_load_tests_apply_scenarios
def test_load_tests_apply_scenarios(self):
suite = load_tests_apply_scenarios(
unittest.TestLoader(),
[self.SampleTest('test_nothing')],
None)
result_tests = list(testtools.iterate_tests(suite))
self.assertEquals(
2,
len(result_tests),
result_tests)
示例10: partition_tests
def partition_tests(suite, count):
"""Partition suite into count lists of tests."""
# This just assigns tests in a round-robin fashion. On one hand this
# splits up blocks of related tests that might run faster if they shared
# resources, but on the other it avoids assigning blocks of slow tests to
# just one partition. So the slowest partition shouldn't be much slower
# than the fastest.
partitions = [list() for _ in range(count)]
tests = iterate_tests(suite)
for partition, test in zip(cycle(partitions), tests):
partition.append(test)
return partitions
示例11: test_load_tests_apply_scenarios_old_style
def test_load_tests_apply_scenarios_old_style(self):
"""Call load_tests in the way used by bzr."""
suite = load_tests_apply_scenarios(
[self.SampleTest('test_nothing')],
self.__class__.__module__,
unittest.TestLoader(),
)
result_tests = list(testtools.iterate_tests(suite))
self.assertEquals(
2,
len(result_tests),
result_tests)
示例12: load_tests
def load_tests(*args):
"""
Wrapper for testscenarios to set the mandatory scenarios variable
only in case a real test loader is in place. Will be automatically
called in case the variable "load_tests" is set.
"""
if getattr(args[0], "suiteClass", None) is not None:
loader, standard_tests, pattern = args
else:
standard_tests, module, loader = args
for test in testtools.iterate_tests(standard_tests):
schema_file = getattr(test, "_schema_file", None)
if schema_file is not None:
setattr(test, "scenarios", NegativeAutoTest.generate_scenario(schema_file))
return testscenarios.load_tests_apply_scenarios(*args)
示例13: test_regular_and_scripts_mixed
def test_regular_and_scripts_mixed(self):
def regular(dir_name, name, suffix=None):
if suffix is None:
suffix = ''
return '''
file: {dir_name}/{name}{suffix}
from sst import cases
class Test_{name}(cases.SSTTestCase):
def test_{name}(self):
pass
'''.format(**locals())
tests.write_tree_from_desc('''dir: tests
file: tests/__init__.py
from sst import loader
discover = loader.discoverRegularTests
''')
tests.write_tree_from_desc(regular('tests', 'test_real', '.py'))
tests.write_tree_from_desc(regular('tests', 'test_real1', '.py'))
tests.write_tree_from_desc(regular('tests', 'test_real2', '.py'))
# Leading '_' => ignored
tests.write_tree_from_desc(regular('tests', '_hidden', '.py'))
# Not a python file => ignored
tests.write_tree_from_desc(regular('tests', 'not-python'))
# Some empty files
tests.write_tree_from_desc('''
file: script1.py
file: script2.py
file: not_a_test
# '.p' is intentional, not a typoed '.py'
file: test_not_a_test.p
_hidden_too.py
''')
test_loader = loader.TestLoader()
suite = test_loader.discoverTests(
'.',
file_loader_class=loader.ScriptLoader,
dir_loader_class=loader.ScriptDirLoader)
self.assertEqual(['script1',
'script2',
'tests.test_real.Test_test_real.test_test_real',
'tests.test_real1.Test_test_real1.test_test_real1',
'tests.test_real2.Test_test_real2.test_test_real2'],
[t.id() for t in testtools.iterate_tests(suite)])
示例14: partition_tests
def partition_tests(suite, count):
# Keep tests from the same class together but allow tests from modules
# to go to different processes to aid parallelisation.
modules = {}
for test in iterate_tests(suite):
m = test.__module__ + "." + test.__class__.__name__
if m not in modules:
modules[m] = []
modules[m].append(test)
# Simply divide the test blocks between the available processes
partitions = [list() for _ in range(count)]
for partition, m in zip(cycle(partitions), modules):
partition.extend(modules[m])
# No point in empty threads so drop them
return [p for p in partitions if p]
示例15: load_tests_input_scenario_utils
def load_tests_input_scenario_utils(*args):
"""
Wrapper for testscenarios to set the scenarios to avoid running a getattr
on the CONF object at import.
"""
if getattr(args[0], 'suiteClass', None) is not None:
loader, standard_tests, pattern = args
else:
standard_tests, module, loader = args
scenario_utils = InputScenarioUtils()
scenario_flavor = scenario_utils.scenario_flavors
scenario_image = scenario_utils.scenario_images
for test in testtools.iterate_tests(standard_tests):
setattr(test, 'scenarios', testscenarios.multiply_scenarios(
scenario_image,
scenario_flavor))
return testscenarios.load_tests_apply_scenarios(*args)