Python unittest.TextTestRunner() Examples
The following are 30
code examples of unittest.TextTestRunner().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unittest
, or try the search function
.
Example #1
Source File: tests.py From pywren-ibm-cloud with Apache License 2.0 | 10 votes |
def run_tests(test_to_run, config=None): global CONFIG, STORAGE_CONFIG, STORAGE CONFIG = json.load(args.config) if config else default_config() STORAGE_CONFIG = extract_storage_config(CONFIG) STORAGE = InternalStorage(STORAGE_CONFIG).storage_handler suite = unittest.TestSuite() if test_to_run == 'all': suite.addTest(unittest.makeSuite(TestPywren)) else: try: suite.addTest(TestPywren(test_to_run)) except ValueError: print("unknown test, use: --help") sys.exit() runner = unittest.TextTestRunner() runner.run(suite)
Example #2
Source File: test.py From pandoc-xnos with GNU General Public License v3.0 | 6 votes |
def main(): """Runs the suite of unit tests""" # Do the tests suite = unittest.TestSuite() suite.addTests(unittest.makeSuite(TestXnos)) suite.addTests(unittest.makeSuite(TestPandocAttributes)) result = unittest.TextTestRunner(verbosity=1).run(suite) n_errors = len(result.errors) n_failures = len(result.failures) if n_errors or n_failures: print('\n\nSummary: %d errors and %d failures reported\n'%\ (n_errors, n_failures)) print() sys.exit(n_errors+n_failures)
Example #3
Source File: test_runner.py From jawfish with MIT License | 6 votes |
def test_startTestRun_stopTestRun_called(self): class LoggingTextResult(LoggingResult): separator2 = '' def printErrors(self): pass class LoggingRunner(unittest.TextTestRunner): def __init__(self, events): super(LoggingRunner, self).__init__(io.StringIO()) self._events = events def _makeResult(self): return LoggingTextResult(self._events) events = [] runner = LoggingRunner(events) runner.run(unittest.TestSuite()) expected = ['startTestRun', 'stopTestRun'] self.assertEqual(events, expected)
Example #4
Source File: gaeunit.py From browserscope with Apache License 2.0 | 6 votes |
def _render_plain(self, package_name, test_name): self.response.headers["Content-Type"] = "text/plain" runner = unittest.TextTestRunner(self.response.out) suite, error = _create_suite(package_name, test_name, _LOCAL_TEST_DIR) if not error: self.response.out.write("====================\n" \ "GAEUnit Test Results\n" \ "====================\n\n") _run_test_suite(runner, suite) else: self.error(404) self.response.out.write(error) ############################################################################## # JSON test classes ##############################################################################
Example #5
Source File: runner.py From github-stats with MIT License | 6 votes |
def main(sdk_path, test_path, test_pattern): # If the SDK path points to a Google Cloud SDK installation # then we should alter it to point to the GAE platform location. if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')): sdk_path = os.path.join(sdk_path, 'platform/google_appengine') # Make sure google.appengine.* modules are importable. fixup_paths(sdk_path) # Make sure all bundled third-party packages are available. import dev_appserver dev_appserver.fix_sys_path() # Loading appengine_config from the current project ensures that any # changes to configuration there are available to all tests (e.g. # sys.path modifications, namespaces, etc.) try: import appengine_config (appengine_config) except ImportError: print('Note: unable to import appengine_config.') # Discover and run tests. suite = unittest.loader.TestLoader().discover(test_path, test_pattern) return unittest.TextTestRunner(verbosity=2).run(suite)
Example #6
Source File: test_runner.py From jawfish with MIT License | 6 votes |
def testRunnerRegistersResult(self): class Test(unittest.TestCase): def testFoo(self): pass originalRegisterResult = unittest.runner.registerResult def cleanup(): unittest.runner.registerResult = originalRegisterResult self.addCleanup(cleanup) result = unittest.TestResult() runner = unittest.TextTestRunner(stream=io.StringIO()) # Use our result object runner._makeResult = lambda: result self.wasRegistered = 0 def fakeRegisterResult(thisResult): self.wasRegistered += 1 self.assertEqual(thisResult, result) unittest.runner.registerResult = fakeRegisterResult runner.run(unittest.TestSuite()) self.assertEqual(self.wasRegistered, 1)
Example #7
Source File: setup.py From throttle with BSD 2-Clause "Simplified" License | 6 votes |
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)
Example #8
Source File: support.py From verge3d-blender-addon with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: py31compat.py From python-netsurv with MIT License | 5 votes |
def unittest_main(*args, **kwargs): if 'testRunner' in kwargs and kwargs['testRunner'] is None: kwargs['testRunner'] = unittest.TextTestRunner return unittest.main(*args, **kwargs)
Example #10
Source File: setup.py From vprof with BSD 2-Clause "Simplified" License | 5 votes |
def run(self): suite = unittest.TestLoader().discover( 'vprof/tests/.', pattern="*_test.py") unittest.TextTestRunner(verbosity=2, buffer=True).run(suite)
Example #11
Source File: setup.py From vprof with BSD 2-Clause "Simplified" License | 5 votes |
def run(self): suite = unittest.TestLoader().discover( 'vprof/tests/.', pattern="*_e2e.py") unittest.TextTestRunner(verbosity=2, buffer=True).run(suite)
Example #12
Source File: tests.py From automatron with Apache License 2.0 | 5 votes |
def run_unit_tests(): ''' Execute Unit Tests ''' tests = unittest.TestLoader().discover('tests/unit') result = unittest.TextTestRunner(verbosity=2).run(tests) return result.wasSuccessful()
Example #13
Source File: test_runner.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_init(self): runner = unittest.TextTestRunner() self.assertFalse(runner.failfast) self.assertFalse(runner.buffer) self.assertEqual(runner.verbosity, 1) self.assertTrue(runner.descriptions) self.assertEqual(runner.resultclass, unittest.TextTestResult)
Example #14
Source File: py31compat.py From pledgeservice with Apache License 2.0 | 5 votes |
def unittest_main(*args, **kwargs): if 'testRunner' in kwargs and kwargs['testRunner'] is None: kwargs['testRunner'] = unittest.TextTestRunner return unittest.main(*args, **kwargs)
Example #15
Source File: doctest.py From pledgeservice with Apache License 2.0 | 5 votes |
def _test(): r = unittest.TextTestRunner() r.run(DocTestSuite())
Example #16
Source File: testrunner.py From pledgeservice with Apache License 2.0 | 5 votes |
def main(sdk_path, test_path): os.chdir('backend') sys.path.extend([sdk_path, '.', '../lib', '../testlib']) import dev_appserver dev_appserver.fix_sys_path() suite = unittest.loader.TestLoader().discover(test_path) if not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful(): sys.exit(-1)
Example #17
Source File: tests.py From automatron with Apache License 2.0 | 5 votes |
def run_functional_tests(): ''' Execute Functional Tests ''' tests = unittest.TestLoader().discover('tests/functional') result = unittest.TextTestRunner(verbosity=2).run(tests) return result.wasSuccessful()
Example #18
Source File: test_runner.py From ironpython2 with Apache License 2.0 | 5 votes |
def testBufferAndFailfast(self): class Test(unittest.TestCase): def testFoo(self): pass result = unittest.TestResult() runner = unittest.TextTestRunner(stream=StringIO(), failfast=True, buffer=True) # Use our result object runner._makeResult = lambda: result runner.run(Test('testFoo')) self.assertTrue(result.failfast) self.assertTrue(result.buffer)
Example #19
Source File: transactions.py From vsphere-storage-for-docker with Apache License 2.0 | 5 votes |
def test(): runner = unittest.TextTestRunner() runner.run(suite())
Example #20
Source File: __init__.py From earthengine with MIT License | 5 votes |
def run(module=None, verbosity=0, stream=None, tests=None, config=None, **kwargs): """Execute self-tests. This raises SelfTestError if any test is unsuccessful. You may optionally pass in a sub-module of SelfTest if you only want to perform some of the tests. For example, the following would test only the hash modules: Crypto.SelfTest.run(Crypto.SelfTest.Hash) """ if config is None: config = {} suite = unittest.TestSuite() if module is None: if tests is None: tests = get_tests(config=config) suite.addTests(tests) else: if tests is None: suite.addTests(module.get_tests(config=config)) else: raise ValueError("'module' and 'tests' arguments are mutually exclusive") if stream is None: kwargs['stream'] = StringIO() runner = unittest.TextTestRunner(verbosity=verbosity, **kwargs) result = runner.run(suite) if not result.wasSuccessful(): if stream is None: sys.stderr.write(stream.getvalue()) raise SelfTestError("Self-test failed", result) return result
Example #21
Source File: __init__.py From mishkal with GNU General Public License v3.0 | 5 votes |
def main(): runner = unittest.TextTestRunner() suite = all_tests_suite() runner.run(suite)
Example #22
Source File: doctest24.py From mishkal with GNU General Public License v3.0 | 5 votes |
def _test(): r = unittest.TextTestRunner() r.run(DocTestSuite())
Example #23
Source File: run.py From PyOne with Mozilla Public License 2.0 | 5 votes |
def test(): """Run the unit tests.""" import unittest tests = unittest.TestLoader().discover('tests') unittest.TextTestRunner(verbosity=2).run(tests) ######################系统日志
Example #24
Source File: manage.py From flask-redis-queue with MIT License | 5 votes |
def test(): """Runs the unit tests without test coverage.""" tests = unittest.TestLoader().discover("project/tests", pattern="test*.py") result = unittest.TextTestRunner(verbosity=2).run(tests) if result.wasSuccessful(): return 0 return 1
Example #25
Source File: manage.py From jbox with MIT License | 5 votes |
def test(): """Run the unit tests""" import unittest tests = unittest.TestLoader.discover('tests') unittest.TextTestRunner(verbosity=2).run(tests)
Example #26
Source File: py31compat.py From jbox with MIT License | 5 votes |
def unittest_main(*args, **kwargs): if 'testRunner' in kwargs and kwargs['testRunner'] is None: kwargs['testRunner'] = unittest.TextTestRunner return unittest.main(*args, **kwargs)
Example #27
Source File: test_log.py From git-aggregator with GNU Affero General Public License v3.0 | 5 votes |
def test_info(self): """ Test log.LogFormatter. """ main.setup_logger(logger, level=logging.INFO) # self._suite = unittest.TestLoader().loadTestsFromName( # 'tests.test_repo.TestRepo.test_multithreading') # unittest.TextTestRunner(verbosity=0).run(self._suite) logger.debug('This message SHOULD NOT be visible.') logger.info('Message from MainThread.') with ThreadNameKeeper(): name = threading.current_thread().name = 'repo_name' logger.info('Message from %s.', name) logger.info('Hello again from MainThread.')
Example #28
Source File: setup.py From browserscope with Apache License 2.0 | 5 votes |
def run(self): """The run method - running the tests on invocation.""" suite = unittest.TestLoader().loadTestsFromTestCase( gviz_api_test.DataTableTest) unittest.TextTestRunner().run(suite)
Example #29
Source File: gaeunit.py From browserscope with Apache License 2.0 | 5 votes |
def _render_plain(package_name, test_name): suite, error = _create_suite(package_name, test_name, _LOCAL_DJANGO_TEST_DIR) if not error: from django.http import HttpResponse response = HttpResponse() response["Content-Type"] = "text/plain" runner = unittest.TextTestRunner(response) response.write("====================\n" \ "GAEUnit Test Results\n" \ "====================\n\n") _run_test_suite(runner, suite) return response else: from django.http import HttpResponseServerError return HttpResponseServerError(error)
Example #30
Source File: main.py From Bowler with MIT License | 5 votes |
def test(codemod: str) -> None: """ Run the tests in the codemod file """ # TODO: Unify the import code between 'run' and 'test' module_name_from_codemod = os.path.basename(codemod).replace(".py", "") spec = importlib.util.spec_from_file_location(module_name_from_codemod, codemod) foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo) suite = unittest.TestLoader().loadTestsFromModule(foo) result = unittest.TextTestRunner().run(suite) sys.exit(not result.wasSuccessful())