本文整理汇总了Python中unittest.BaseTestSuite方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.BaseTestSuite方法的具体用法?Python unittest.BaseTestSuite怎么用?Python unittest.BaseTestSuite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest
的用法示例。
在下文中一共展示了unittest.BaseTestSuite方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assert_garbage_collect_test_after_run
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def assert_garbage_collect_test_after_run(self, TestSuiteClass):
if not unittest.BaseTestSuite._cleanup:
raise unittest.SkipTest("Suite cleanup is disabled")
class Foo(unittest.TestCase):
def test_nothing(self):
pass
test = Foo('test_nothing')
wref = weakref.ref(test)
suite = TestSuiteClass([wref()])
suite.run(unittest.TestResult())
del test
# for the benefit of non-reference counting implementations
gc.collect()
self.assertEqual(suite._tests, [None])
self.assertIsNone(wref())
示例2: set_timeout
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def set_timeout(testsuite, seconds=None):
"""
add timout to test case if it didn't have one,
@param testsuite testsuite form loader()
@param seconds: timeout seconds
@return: updated testsuite
"""
def _testset(testsuite):
"""interate tcs in testsuite"""
for each in testsuite:
if not isinstance(each, unittest.BaseTestSuite):
yield each
else:
for each2 in _testset(each):
yield each2
if seconds:
for tc in _testset(testsuite):
assert hasattr(tc, "_testMethodName"), \
"%s is not an unittest.TestCase object"
testMethod = getattr(tc, tc._testMethodName)
test_func = testMethod.im_func
if not hastimeout(test_func):
tc.run = timeout(seconds)(tc.run)
return testsuite
示例3: test_basetestsuite
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_basetestsuite(self):
class Test(unittest.TestCase):
wasSetUp = False
wasTornDown = False
@classmethod
def setUpClass(cls):
cls.wasSetUp = True
@classmethod
def tearDownClass(cls):
cls.wasTornDown = True
def testPass(self):
pass
def testFail(self):
fail
class Module(object):
wasSetUp = False
wasTornDown = False
@staticmethod
def setUpModule():
Module.wasSetUp = True
@staticmethod
def tearDownModule():
Module.wasTornDown = True
Test.__module__ = 'Module'
sys.modules['Module'] = Module
self.addCleanup(sys.modules.pop, 'Module')
suite = unittest.BaseTestSuite()
suite.addTests([Test('testPass'), Test('testFail')])
self.assertEqual(suite.countTestCases(), 2)
result = unittest.TestResult()
suite.run(result)
self.assertFalse(Module.wasSetUp)
self.assertFalse(Module.wasTornDown)
self.assertFalse(Test.wasSetUp)
self.assertFalse(Test.wasTornDown)
self.assertEqual(len(result.errors), 1)
self.assertEqual(len(result.failures), 0)
self.assertEqual(result.testsRun, 2)
示例4: test_remove_test_at_index
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_remove_test_at_index(self):
if not unittest.BaseTestSuite._cleanup:
raise unittest.SkipTest("Suite cleanup is disabled")
suite = unittest.TestSuite()
suite._tests = [1, 2, 3]
suite._removeTestAtIndex(1)
self.assertEqual([1, None, 3], suite._tests)
示例5: test_remove_test_at_index_not_indexable
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_remove_test_at_index_not_indexable(self):
if not unittest.BaseTestSuite._cleanup:
raise unittest.SkipTest("Suite cleanup is disabled")
suite = unittest.TestSuite()
suite._tests = None
# if _removeAtIndex raises for noniterables this next line will break
suite._removeTestAtIndex(2)
示例6: test_garbage_collect_test_after_run_BaseTestSuite
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def test_garbage_collect_test_after_run_BaseTestSuite(self):
self.assert_garbage_collect_test_after_run(unittest.BaseTestSuite)
示例7: flattenTestSuite
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def flattenTestSuite(test_suite, module=None):
# Look for a `doctest_modules` list and attempt to add doctest tests to the
# suite of tests that we are about to flatten.
# todo: rename this function to something more appropriate.
suites = [test_suite]
doctest_modules = getattr(module, "doctest_modules", ())
for doctest_module in doctest_modules:
suite = DocTestSuite(doctest_module)
suite.injected_module = module.__name__
suites.append(suite)
# Now extract all tests from the suite heirarchies and flatten them into a
# single suite with all tests.
tests = []
for suite in suites:
injected_module = None
if getattr(suite, "injected_module", None):
injected_module = suite.injected_module
for test in suite:
if injected_module:
# For doctests, inject the test module name so we can later
# grab it and use it to group the doctest output along with the
# test module which specified it should be run.
test.__module__ = injected_module
if isinstance(test, unittest.BaseTestSuite):
tests.extend(flattenTestSuite(test))
else:
tests.append(test)
return GreenTestLoader.suiteClass(tests)
示例8: filter_tagexp
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import BaseTestSuite [as 别名]
def filter_tagexp(testsuite, tagexp):
"""filter according to true or flase of tag expression"""
if not tagexp:
return testsuite
caselist = []
for each in testsuite:
if not isinstance(each, unittest.BaseTestSuite):
if checktags(each, tagexp):
caselist.append(each)
else:
caselist.append(filter_tagexp(each, tagexp))
return testsuite.__class__(caselist)