def run(): loader = TestLoader() suite = loader.loadPackage(lbrynet.tests, True) runner = TrialRunner(AndroidTestReporter) runner.stream = str_stream passFail = not runner.run(suite).wasSuccessful() print str_stream.getvalue() sys.exit(passFail)
runner = TrialRunner(VerboseTextReporter, workingDirectory=workingDir) suite = TestSuite() # find all tests print "searching for test cases ..." loader = TestLoader() for root,dirs,files in os.walk('.'): for name in files: if name.startswith('test_') and name.endswith('.py'): module = loader.findByName(os.path.join(root,name)) classes = loader.findTestClasses(module) if len(classes) > 0: for cls in classes: methods = loader.getTestCaseNames(cls) if len(methods) > 0: for method in methods: methodName = loader.methodPrefix + method print "found %s" % methodName suite.addTest(cls(methodName, fixtureDir, workingDir)) print "" print "running test cases ..." print "" result = runner.run(suite) status = result.wasSuccessful() except Exception, e: print "testtool.py failed: %s" % str(e) status = 1 finally: _recursiveDelete(workingDir) sys.exit(status)
def runtests(root_dir='pyofwave'): runner = TrialRunner(TreeReporter) loader = TestLoader() failures = runner.run(loader.loadByName(root_dir, recurse=True)) sys.exit(failures)
def test_with_trial(options, topdir, testdirs, testpaths): """The main testing entry point.""" # parse arguments # Ensure that the database watcher is installed early, so that # unexpected database access can be blocked. from backends.testing.resources import DatabaseResource watcher = DatabaseResource.get_watcher() watcher.enable('account') reporter_decorators = [] if options.one: reporter_decorators.append(StopOnFailureDecorator) if options.logs_on_failure: reporter_decorators.append(LogsOnFailureDecorator) def factory(*args, **kwargs): """Custom factory tha apply the decorators to the TreeReporter""" if options.subunit: return SubunitReporter(*args, **kwargs) else: result = TreeReporter(*args, **kwargs) for decorator in reporter_decorators: result = decorator(result) return result reporterFactory = factory runner = TrialRunner(reporterFactory=reporterFactory, realTimeErrors=True, workingDirectory=WORKING_DIR) suite = UnsortedOptimisingTestSuite() suite.adsorbSuite(collect_tests(topdir, testdirs, testpaths)) if options.test: old_suite = suite suite = UnsortedOptimisingTestSuite() pattern = re.compile('.*%s.*' % options.test) for test in iter(old_suite): if pattern.match(test.id()): suite.addTest(test) if options.ignore: old_suite = suite suite = UnsortedOptimisingTestSuite() pattern = re.compile('.*%s.*' % options.ignore) for test in iter(old_suite): if not pattern.match(test.id()): suite.addTest(test) if options.loops > 1: # we could loop the .run() call, but creating a suite that contains # duplicate tests is more efficient and more likely to expose # test-to-test issues. Plus, the testrun summary reports are nicer # this way --gafton old_suite = suite suite = UnsortedOptimisingTestSuite() for x in xrange(options.loops): suite.addTest(old_suite) if options.debug: DelayedCall.debug = True watcher.disable('account') if options.coverage: tracer = trace.Trace(trace=False, count=True) tracer.runctx('runner.run(suite)', globals=globals(), locals=vars()) r = tracer.results() if not os.path.exists(COVERAGE_DIR): os.mkdir(COVERAGE_DIR) r.write_results(show_missing=True, summary=True, coverdir=COVERAGE_DIR) else: result = runner.run(suite) return not result.wasSuccessful()