本文整理汇总了Python中unittest2.TestSuite方法的典型用法代码示例。如果您正苦于以下问题:Python unittest2.TestSuite方法的具体用法?Python unittest2.TestSuite怎么用?Python unittest2.TestSuite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest2
的用法示例。
在下文中一共展示了unittest2.TestSuite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _run_suite
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def _run_suite(suite):
"""Run tests from a unittest.TestSuite-derived class."""
if verbose:
runner = unittest.TextTestRunner(sys.stdout, verbosity=2,
failfast=failfast)
else:
runner = BasicTestRunner()
result = runner.run(suite)
if not result.wasSuccessful():
if len(result.errors) == 1 and not result.failures:
err = result.errors[0][1]
elif len(result.failures) == 1 and not result.errors:
err = result.failures[0][1]
else:
err = "multiple errors occurred"
if not verbose: err += "; run in verbose mode for details"
raise TestFailed(err)
示例2: run
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def run(self):
"""Run the test suite."""
try:
import unittest2 as unittest
except ImportError:
import unittest
if self.verbose:
verbosity=1
else:
verbosity=0
loader = unittest.defaultTestLoader
suite = unittest.TestSuite()
if self.test_suite == self.DEFAULT_TEST_SUITE:
for test_module in loader.discover('.'):
suite.addTest(test_module)
else:
suite.addTest(loader.loadTestsFromName(self.test_suite))
result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
if not result.wasSuccessful():
sys.exit(1)
示例3: exclude_tests
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def exclude_tests(suite, blacklist):
"""
Example:
blacklist = [
'test_some_test_that_should_be_skipped',
'test_another_test_that_should_be_skipped'
]
"""
new_suite = unittest.TestSuite()
for test_group in suite._tests:
for test in test_group:
if not hasattr(test, '_tests'):
# e.g. ModuleImportFailure
new_suite.addTest(test)
continue
for subtest in test._tests:
method = subtest._testMethodName
if method in blacklist:
setattr(test,
method,
getattr(SkipCase(), 'skeleton_run_test'))
new_suite.addTest(test)
return new_suite
示例4: testRunnerRegistersResult
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def testRunnerRegistersResult(self):
class Test(unittest2.TestCase):
def testFoo(self):
pass
originalRegisterResult = unittest2.runner.registerResult
def cleanup():
unittest2.runner.registerResult = originalRegisterResult
self.addCleanup(cleanup)
result = unittest2.TestResult()
runner = unittest2.TextTestRunner(stream=StringIO())
# Use our result object
runner._makeResult = lambda: result
self.wasRegistered = 0
def fakeRegisterResult(thisResult):
self.wasRegistered += 1
self.assertEqual(thisResult, result)
unittest2.runner.registerResult = fakeRegisterResult
runner.run(unittest2.TestSuite())
self.assertEqual(self.wasRegistered, 1)
示例5: test_startTestRun_stopTestRun_called
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_startTestRun_stopTestRun_called(self):
class LoggingTextResult(LoggingResult):
separator2 = ''
def printErrors(self):
pass
class LoggingRunner(unittest2.TextTestRunner):
def __init__(self, events):
super(LoggingRunner, self).__init__(StringIO())
self._events = events
def _makeResult(self):
return LoggingTextResult(self._events)
events = []
runner = LoggingRunner(events)
runner.run(unittest2.TestSuite())
expected = ['startTestRun', 'stopTestRun']
self.assertEqual(events, expected)
示例6: test_loadTestsFromTestCase__no_matches
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromTestCase__no_matches(self):
class Foo(unittest2.TestCase):
def foo_bar(self): pass
empty_suite = unittest2.TestSuite()
loader = unittest2.TestLoader()
self.assertEqual(loader.loadTestsFromTestCase(Foo), empty_suite)
# "Return a suite of all tests cases contained in the TestCase-derived
# class testCaseClass"
#
# What happens if loadTestsFromTestCase() is given an object
# that isn't a subclass of TestCase? Specifically, what happens
# if testCaseClass is a subclass of TestSuite?
#
# This is checked for specifically in the code, so we better add a
# test for it.
示例7: test_loadTestsFromTestCase__TestSuite_subclass
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromTestCase__TestSuite_subclass(self):
class NotATestCase(unittest2.TestSuite):
pass
loader = unittest2.TestLoader()
try:
loader.loadTestsFromTestCase(NotATestCase)
except TypeError:
pass
else:
self.fail('Should raise TypeError')
# "Return a suite of all tests cases contained in the TestCase-derived
# class testCaseClass"
#
# Make sure loadTestsFromTestCase() picks up the default test method
# name (as specified by TestCase), even though the method name does
# not match the default TestLoader.testMethodPrefix string
示例8: test_loadTestsFromModule__not_a_module
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromModule__not_a_module(self):
class MyTestCase(unittest2.TestCase):
def test(self):
pass
class NotAModule(object):
test_2 = MyTestCase
loader = unittest2.TestLoader()
suite = loader.loadTestsFromModule(NotAModule)
reference = [unittest2.TestSuite([MyTestCase('test')])]
self.assertEqual(list(suite), reference)
# Check that loadTestsFromModule honors (or not) a module
# with a load_tests function.
示例9: test_loadTestsFromModule__load_tests
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromModule__load_tests(self):
m = types.ModuleType('m')
class MyTestCase(unittest2.TestCase):
def test(self):
pass
m.testcase_1 = MyTestCase
load_tests_args = []
def load_tests(loader, tests, pattern):
self.assertIsInstance(tests, unittest2.TestSuite)
load_tests_args.extend((loader, tests, pattern))
return tests
m.load_tests = load_tests
loader = unittest2.TestLoader()
suite = loader.loadTestsFromModule(m)
self.assertIsInstance(suite, unittest2.TestSuite)
self.assertEquals(load_tests_args, [loader, suite, None])
load_tests_args = []
suite = loader.loadTestsFromModule(m, use_load_tests=False)
self.assertEquals(load_tests_args, [])
示例10: test_loadTestsFromName__relative_empty_name
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromName__relative_empty_name(self):
loader = unittest2.TestLoader()
try:
loader.loadTestsFromName('', unittest2)
except AttributeError:
pass
else:
self.fail("Failed to raise AttributeError")
# "The specifier name is a ``dotted name'' that may resolve either to
# a module, a test case class, a TestSuite instance, a test method
# within a test case class, or a callable object which returns a
# TestCase or TestSuite instance."
# ...
# "The method optionally resolves name relative to the given module"
#
# What happens when an impossible name is given, relative to the provided
# `module`?
示例11: test_loadTestsFromName__relative_not_a_module
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromName__relative_not_a_module(self):
class MyTestCase(unittest2.TestCase):
def test(self):
pass
class NotAModule(object):
test_2 = MyTestCase
loader = unittest2.TestLoader()
suite = loader.loadTestsFromName('test_2', NotAModule)
reference = [MyTestCase('test')]
self.assertEqual(list(suite), reference)
# "The specifier name is a ``dotted name'' that may resolve either to
# a module, a test case class, a TestSuite instance, a test method
# within a test case class, or a callable object which returns a
# TestCase or TestSuite instance."
#
# Does it raise an exception if the name resolves to an invalid
# object?
示例12: test_loadTestsFromName__relative_TestCase_subclass
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromName__relative_TestCase_subclass(self):
m = types.ModuleType('m')
class MyTestCase(unittest2.TestCase):
def test(self):
pass
m.testcase_1 = MyTestCase
loader = unittest2.TestLoader()
suite = loader.loadTestsFromName('testcase_1', m)
self.assertIsInstance(suite, loader.suiteClass)
self.assertEqual(list(suite), [MyTestCase('test')])
# "The specifier name is a ``dotted name'' that may resolve either to
# a module, a test case class, a TestSuite instance, a test method
# within a test case class, or a callable object which returns a
# TestCase or TestSuite instance."
示例13: test_loadTestsFromName__relative_testmethod
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromName__relative_testmethod(self):
m = types.ModuleType('m')
class MyTestCase(unittest2.TestCase):
def test(self):
pass
m.testcase_1 = MyTestCase
loader = unittest2.TestLoader()
suite = loader.loadTestsFromName('testcase_1.test', m)
self.assertIsInstance(suite, loader.suiteClass)
self.assertEqual(list(suite), [MyTestCase('test')])
# "The specifier name is a ``dotted name'' that may resolve either to
# a module, a test case class, a TestSuite instance, a test method
# within a test case class, or a callable object which returns a
# TestCase or TestSuite instance."
#
# Does loadTestsFromName() raise the proper exception when trying to
# resolve "a test method within a test case class" that doesn't exist
# for the given name (relative to a provided module)?
示例14: test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromName__callable__TestCase_instance_ProperSuiteClass(self):
class SubTestSuite(unittest2.TestSuite):
pass
m = types.ModuleType('m')
testcase_1 = unittest2.FunctionTestCase(lambda: None)
def return_TestCase():
return testcase_1
m.return_TestCase = return_TestCase
loader = unittest2.TestLoader()
loader.suiteClass = SubTestSuite
suite = loader.loadTestsFromName('return_TestCase', m)
self.assertIsInstance(suite, loader.suiteClass)
self.assertEqual(list(suite), [testcase_1])
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a test method within a test case class"
#*****************************************************************
#Override the suiteClass attribute to ensure that the suiteClass
#attribute is used
示例15: test_loadTestsFromName__relative_testmethod_ProperSuiteClass
# 需要导入模块: import unittest2 [as 别名]
# 或者: from unittest2 import TestSuite [as 别名]
def test_loadTestsFromName__relative_testmethod_ProperSuiteClass(self):
class SubTestSuite(unittest2.TestSuite):
pass
m = types.ModuleType('m')
class MyTestCase(unittest2.TestCase):
def test(self):
pass
m.testcase_1 = MyTestCase
loader = unittest2.TestLoader()
loader.suiteClass=SubTestSuite
suite = loader.loadTestsFromName('testcase_1.test', m)
self.assertIsInstance(suite, loader.suiteClass)
self.assertEqual(list(suite), [MyTestCase('test')])
# "The specifier name is a ``dotted name'' that may resolve ... to
# ... a callable object which returns a TestCase or TestSuite instance"
#
# What happens if the callable returns something else?