本文整理汇总了Python中unittest.defaultTestLoader.loadTestsFromTestCase函数的典型用法代码示例。如果您正苦于以下问题:Python loadTestsFromTestCase函数的具体用法?Python loadTestsFromTestCase怎么用?Python loadTestsFromTestCase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadTestsFromTestCase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: suite
def suite():
suite = TestSuite()
suite.addTests(
defaultTestLoader.loadTestsFromTestCase(TestSubmissionModule))
suite.addTests(
defaultTestLoader.loadTestsFromTestCase(TestSubmission))
return suite
示例2: tests
def tests(self):
from unittest import defaultTestLoader
yield defaultTestLoader.loadTestsFromTestCase(DetectorTest)
yield defaultTestLoader.loadTestsFromTestCase(ImporterTest)
from hwp5_uno.tests import test_hwp5_uno
yield defaultTestLoader.loadTestsFromModule(test_hwp5_uno)
from hwp5.tests import test_suite
yield test_suite()
示例3: suite
def suite():
from unittest import TestSuite, defaultTestLoader
suite = TestSuite()
suite.addTests(defaultTestLoader.loadTestsFromTestCase(LibraryAccessionTestCase))
suite.addTests(defaultTestLoader.loadTestsFromTestCase(LibraryTestCase))
suite.addTests(defaultTestLoader.loadTestsFromTestCase(SampleWebTestCase))
suite.addTests(defaultTestLoader.loadTestsFromTestCase(TestRDFaLibrary))
return suite
示例4: suite
def suite():
from unittest import TestSuite, defaultTestLoader
suite = TestSuite()
suite.addTests(defaultTestLoader.loadTestsFromTestCase(MatchCodeTests))
suite.addTests(defaultTestLoader.loadTestsFromTestCase(TestMappedReads))
suite.addTests(defaultTestLoader.loadTestsFromTestCase(ElandTests))
suite.addTests(defaultTestLoader.loadTestsFromTestCase(TestElandMatches))
return suite
示例5: _execute_test
def _execute_test(cls, test: FirmwareTestClass, router: Router, routers: List[Router]) -> TestResult:
if not isinstance(router, Router):
raise ValueError("Chosen Router is not a real Router...")
# proofed: this method runs in other process as the server
setproctitle(str(router.id) + " - " + str(test))
logging.debug("%sExecute test " + str(test) + " on Router(" + str(router.id) + ")", LoggerSetup.get_log_deep(2))
test_suite = defaultTestLoader.loadTestsFromTestCase(test)
# prepare all test cases
for test_case in test_suite:
logging.debug("%sTestCase " + str(test_case), LoggerSetup.get_log_deep(4))
test_case.prepare(router, routers)
result = TestResult()
cls.__setns(router)
try:
result = test_suite.run(result)
except Exception as e:
logging.error("%sTestCase execution raised an exception", LoggerSetup.get_log_deep(3))
logging.error("%s" + str(e), LoggerSetup.get_log_deep(3))
test_obj = test()
result.addError(test_obj, sys.exc_info()) # add the reason of the exception
finally:
# I'm sry for this dirty hack, but if you don't do this you get an
# "TypeError: cannot serialize '_io.TextIOWrapper' object" because sys.stdout is not serializeable...
result._original_stdout = None
result._original_stderr = None
logging.debug("%sResult from test " + str(result), LoggerSetup.get_log_deep(3))
return result
示例6: suite
def suite():
from unittest import TestSuite, defaultTestLoader
suite = TestSuite()
for testcase in [ExerimentsTestCases,
TestEmailNotify,
TestSequencer]:
suite.addTests(defaultTestLoader.loadTestsFromTestCase(testcase))
return suite
示例7: test_with_stdout
def test_with_stdout(self):
class LoudTestCase(TestCase):
def test(self):
print('True is true, who knew!')
self.assertTrue(True)
loud_suite = TestSuite(
tests=defaultTestLoader.loadTestsFromTestCase(LoudTestCase)
)
with self.assertRaises(RuntimeError):
self._run_suite(loud_suite)
示例8: test_with_no_stdout
def test_with_no_stdout(self):
class QuietTestCase(TestCase):
def test(self):
self.assertTrue(True)
quiet_suite = TestSuite(
tests=defaultTestLoader.loadTestsFromTestCase(QuietTestCase)
)
result = self._run_suite(quiet_suite)
# No errors should be raised and the suite should have passed
self.assertEqual(result.errors, [])
self.assertEqual(result.failures, [])
示例9: main
def main(path="."):
wasSuccessful = True
suites = TestSuite()
#path = os.path.abspath(path)
print "path='%s'" % path
if type(path) is type([]):
paths = [os.path.abspath(p) for p in path]
[sys.path.append(p) for p in paths]
else:
if os.path.split(path)[1]=="apps":
paths = []
sys.path.append(path)
for file in os.listdir(path):
p = os.path.join(path, file)
if os.path.isdir(p) and not file.startswith("."):
paths.append(p)
sys.path.append(p)
print
print "**********************"
print "%s" % paths
print "**********************"
print
else:
sys.path.append(path)
paths = [path]
for path in paths:
os.chdir(path)
print
print "**********************"
print "Processing '%s'" % path
print "**********************"
print
testClasses = getAllTestClasses(path=path)
for filename, testClassName, testClass in testClasses:
suite = defaultTestLoader.loadTestsFromTestCase(testClass)
print "file='%s', class='%s', test=%s" % (filename, testClassName, suite.countTestCases())
#result = TextTestRunner(verbosity=1).run(suite)
#if not result.wasSuccessful:
# wasSuccessful = False
suites.addTest(suite)
result = TextTestRunner(verbosity=1).run(suites)
if result.wasSuccessful==False:
wasSuccessful = False
if wasSuccessful:
print "Completed all tests OK."
return True
else:
print "*** One or more tests Failed! ***"
return result
示例10: test_with_stdout
def test_with_stdout(self):
class LoudTestCase(TestCase):
def test(self):
print('True is true, who knew!')
self.assertTrue(True)
loud_suite = TestSuite(
tests=defaultTestLoader.loadTestsFromTestCase(LoudTestCase)
)
with self.assertRaises(AssertionError):
StdoutCapturingTestRunner(verbosity=0).run_suite(
loud_suite,
stream=StringIO()
)
示例11: test_with_no_stdout
def test_with_no_stdout(self):
class QuietTestCase(TestCase):
def test(self):
self.assertTrue(True)
quiet_suite = TestSuite(
tests=defaultTestLoader.loadTestsFromTestCase(QuietTestCase)
)
# Supress test case output while this runs so we don't get weird
# test-case-in-our-test-case messaging
result = StdoutCapturingTestRunner().run_suite(
quiet_suite,
stream=StringIO()
)
# No errors should be raised and the suite should have passed
self.assertEqual(result.errors, [])
self.assertEqual(result.failures, [])
示例12: RunTests
def RunTests():
global TestLoader, TextTestRunner, MemoryCtx
tests = [
TestScAddr,
TestScType,
TestScMemoryContext,
TestScSet,
TestEvents,
TestScHelper,
]
for testItem in tests:
testItem.MemoryCtx = MemoryCtx
testItem.module = module
suite = defaultTestLoader.loadTestsFromTestCase(testItem)
res = TextTestRunner(verbosity=2).run(suite)
if not res.wasSuccessful():
raise Exception("Unit test failed")
示例13: selftest
def selftest(logger):
selftest_started = time.perf_counter()
result = SelfTestResult()
test_suite = TestSuite()
for test_case in SELFTEST_CASES:
test_suite.addTest(defaultTestLoader.loadTestsFromTestCase(test_case))
test_suite.run(result)
result.log_results(logger)
successful_tests = result.successful_test_count()
count_mismatch = successful_tests != SELFTEST_COUNT
if result.wasSuccessful() and count_mismatch:
# only print this if all tests succeeded
logger.error("self test count (%d != %d) mismatch, either test discovery is broken or a test was added "
"without updating borg.selftest",
successful_tests, SELFTEST_COUNT)
if not result.wasSuccessful() or count_mismatch:
logger.error("self test failed\n"
"This is a bug either in Borg or in the package / distribution you use.")
sys.exit(2)
assert False, "sanity assertion failed: ran beyond sys.exit()"
selftest_elapsed = time.perf_counter() - selftest_started
logger.debug("%d self tests completed in %.2f seconds", successful_tests, selftest_elapsed)
示例14: main
def main(path="."):
wasSuccessful = True
suites = TestSuite()
#path = os.path.abspath(path)
path = fs.absPath(path)
print "path='%s'" % path
if fs.split(path)[1]=="apps":
paths = []
#for file in os.listdir(path):
for file in fs.list(path):
#p = os.path.join(path, file)
p = fs.join(path, file)
#if os.path.isdir(p) and not file.startswith("."):
if fs.isDirectory(p) and not file.startswith("."):
paths.append(p)
else:
paths = [path]
for path in paths:
#No chdir method id FileSystem
os.chdir(path)
print "Processing '%s'" % path
testClasses = getAllTestClasses(path=path)
for filename, testClassName, testClass in testClasses:
suite = defaultTestLoader.loadTestsFromTestCase(testClass)
print "file='%s', class='%s', test=%s" % (filename, testClassName, suite.countTestCases())
#result = TextTestRunner(verbosity=1).run(suite)
#if not result.wasSuccessful:
# wasSuccessful = False
suites.addTest(suite)
result = TextTestRunner(verbosity=1).run(suites)
if result.wasSuccessful==False:
wasSuccessful = False
if wasSuccessful:
print "Completed all tests OK."
return True
else:
print "*** One or more tests Failed! ***"
return result
示例15:
from unittest import defaultTestLoader
from TransactionManager import TransactionManagerBase
test_cases = [TransactionManagerBase]
tests = [defaultTestLoader.loadTestsFromTestCase(test) for test in test_cases]