def run(self, suite): "Run the given test case or test suite." result = GreenTestResult( self.stream, self.descriptions, self.verbosity, html=self.html, termcolor=self.termcolor) registerResult(result) with warnings.catch_warnings(): if self.warnings: # if self.warnings is set, use it to filter all the warnings warnings.simplefilter(self.warnings) # if the filter is 'default' or 'always', special-case the # warnings from the deprecated unittest methods to show them # no more than once per module, because they can be fairly # noisy. The -Wd and -Wa flags can be used to bypass this # only when self.warnings is None. if self.warnings in ['default', 'always']: warnings.filterwarnings('module', category=DeprecationWarning, message='Please use assert\w+ instead.') result.startTestRun() if self.subprocesses == 1: suite.run(result) else: tests = toProtoTestList(suite) pool = LoggingDaemonlessPool(processes=self.subprocesses) if tests: async_responses = [] for index, test in enumerate(tests): if self.run_coverage: coverage_number = index + 1 else: coverage_number = None async_responses.append(pool.apply_async( poolRunner, (test.dotted_name, coverage_number, self.omit))) pool.close() for test, async_response in zip(tests, async_responses): # Prints out the white 'processing...' version of the output result.startTest(test) # This blocks until the worker who is processing this # particular test actually finishes result.addProtoTestResult(async_response.get()) pool.terminate() pool.join() result.stopTestRun() return result
def test_addProtoTestResult(self): """ addProtoTestResult adds the correct things to the correct places. """ ptr = ProtoTestResult() err_t = proto_test(MagicMock()) try: raise Exception except: err_e = proto_error(sys.exc_info()) ptr.addError(err_t, err_e) ef_t = proto_test(MagicMock()) try: raise Exception except: ef_e = proto_error(sys.exc_info()) ptr.addExpectedFailure(ef_t, ef_e) fail_t = proto_test(MagicMock()) try: raise Exception except: fail_e = proto_error(sys.exc_info()) ptr.addFailure(fail_t, fail_e) pass_t = proto_test(MagicMock()) ptr.addSuccess(pass_t) skip_t = proto_test(MagicMock()) skip_r = proto_test(MagicMock()) ptr.addSkip(skip_t, skip_r) us_t = proto_test(MagicMock()) ptr.addUnexpectedSuccess(us_t) self.args.verbose = 0 gtr = GreenTestResult(self.args, GreenStream(self.stream)) gtr.addProtoTestResult(ptr) self.assertEqual(gtr.errors, [(err_t, err_e)]) self.assertEqual(gtr.expectedFailures, [(ef_t, ef_e)]) self.assertEqual(gtr.failures, [(fail_t, fail_e)]) self.assertEqual(gtr.passing, [pass_t]) self.assertEqual(gtr.skipped, [(skip_t, skip_r)]) self.assertEqual(gtr.unexpectedSuccesses, [us_t])
def run(suite, stream, args, testing=False): """ Run the given test case or test suite with the specified arguments. Any args.stream passed in will be wrapped in a GreenStream """ if not issubclass(GreenStream, type(stream)): stream = GreenStream(stream, disable_windows=args.disable_windows) result = GreenTestResult(args, stream) # Note: Catching SIGINT isn't supported by Python on windows (python # "WONTFIX" issue 18040) installHandler() registerResult(result) with warnings.catch_warnings(): if args.warnings: # pragma: no cover # if args.warnings is set, use it to filter all the warnings warnings.simplefilter(args.warnings) # if the filter is 'default' or 'always', special-case the # warnings from the deprecated unittest methods to show them # no more than once per module, because they can be fairly # noisy. The -Wd and -Wa flags can be used to bypass this # only when args.warnings is None. if args.warnings in ['default', 'always']: warnings.filterwarnings( 'module', category=DeprecationWarning, message='Please use assert\w+ instead.') result.startTestRun() pool = LoggingDaemonlessPool( processes=args.processes or None, initializer=InitializerOrFinalizer(args.initializer), finalizer=InitializerOrFinalizer(args.finalizer)) manager = multiprocessing.Manager() targets = [(target, manager.Queue()) for target in toParallelTargets(suite, args.targets)] if targets: for index, (target, queue) in enumerate(targets): if args.run_coverage: coverage_number = index + 1 else: coverage_number = None debug("Sending {} to runner {}".format(target, poolRunner)) pool.apply_async( poolRunner, (target, queue, coverage_number, args.omit_patterns)) pool.close() for target, queue in targets: abort = False while True: msg = queue.get() # Sentinel value, we're done if not msg: break else: # Result guaranteed after this message, we're # currently waiting on this test, so print out # the white 'processing...' version of the output result.startTest(msg) proto_test_result = queue.get() result.addProtoTestResult(proto_test_result) if result.shouldStop: abort = True break if abort: break pool.close() pool.join() result.stopTestRun() removeResult(result) return result
def run(suite, stream, args, testing=False): """ Run the given test case or test suite with the specified arguments. Any args.stream passed in will be wrapped in a GreenStream """ if not issubclass(GreenStream, type(stream)): stream = GreenStream(stream) result = GreenTestResult(args, stream) # Note: Catching SIGINT isn't supported by Python on windows (python # "WONTFIX" issue 18040) installHandler() registerResult(result) with warnings.catch_warnings(): if args.warnings: # pragma: no cover # if args.warnings is set, use it to filter all the warnings warnings.simplefilter(args.warnings) # if the filter is 'default' or 'always', special-case the # warnings from the deprecated unittest methods to show them # no more than once per module, because they can be fairly # noisy. The -Wd and -Wa flags can be used to bypass this # only when args.warnings is None. if args.warnings in ['default', 'always']: warnings.filterwarnings('module', category=DeprecationWarning, message='Please use assert\w+ instead.') result.startTestRun() pool = LoggingDaemonlessPool(processes=args.processes or None, initializer=InitializerOrFinalizer(args.initializer), finalizer=InitializerOrFinalizer(args.finalizer)) manager = multiprocessing.Manager() targets = [(target, manager.Queue()) for target in toParallelTargets(suite, args.targets)] if targets: for index, (target, queue) in enumerate(targets): if args.run_coverage: coverage_number = index + 1 else: coverage_number = None pool.apply_async( poolRunner, (target, queue, coverage_number, args.omit_patterns)) pool.close() for target, queue in targets: abort = False while True: msg = queue.get() # Sentinel value, we're done if not msg: break else: # Result guarunteed after this message, we're # currently waiting on this test, so print out # the white 'processing...' version of the output result.startTest(msg) proto_test_result = queue.get() result.addProtoTestResult(proto_test_result) if result.shouldStop: abort = True break if abort: break pool.close() pool.join() result.stopTestRun() removeResult(result) return result
def run(suite, stream, args, testing=False): """ Run the given test case or test suite with the specified arguments. Any args.stream passed in will be wrapped in a GreenStream """ # check if the kubefwd is running, then stop the run if check_kubefwd_running(): return GreenTestResult(args, stream) if not issubclass(GreenStream, type(stream)): stream = GreenStream( stream, disable_windows=args.disable_windows, disable_unidecode=args.disable_unidecode, ) result = GreenTestResult(args, stream) # Note: Catching SIGINT isn't supported by Python on windows (python # "WONTFIX" issue 18040) installHandler() registerResult(result) with warnings.catch_warnings(): if args.warnings: # pragma: no cover # if args.warnings is set, use it to filter all the warnings warnings.simplefilter(args.warnings) # if the filter is 'default' or 'always', special-case the # warnings from the deprecated unittest methods to show them # no more than once per module, because they can be fairly # noisy. The -Wd and -Wa flags can be used to bypass this # only when args.warnings is None. if args.warnings in ["default", "always"]: warnings.filterwarnings( "module", category=DeprecationWarning, message="Please use assert\w+ instead.", ) result.startTestRun() # The call to toParallelTargets needs to happen before pool stuff so we can crash if there # are, for example, syntax errors in the code to be loaded. parallel_targets = toParallelTargets(suite, args.targets) pool = LoggingDaemonlessPool( processes=args.processes or None, initializer=InitializerOrFinalizer(args.initializer), finalizer=InitializerOrFinalizer(args.finalizer), ) manager = multiprocessing.Manager() targets = [(target, manager.Queue()) for target in parallel_targets] if targets: for index, (target, queue) in enumerate(targets): if args.run_coverage: coverage_number = index + 1 else: coverage_number = None debug("Sending {} to poolRunner {}".format(target, poolRunner)) pool.apply_async( poolRunner, ( target, queue, coverage_number, args.omit_patterns, args.cov_config_file, ), ) pool.close() for target, queue in targets: abort = False while True: msg = queue.get() # Sentinel value, we're done if not msg: debug("runner.run(): received sentinal, breaking.", 3) break else: debug("runner.run(): start test: {}".format(msg)) # Result guaranteed after this message, we're # currently waiting on this test, so print out # the white 'processing...' version of the output result.startTest(msg) proto_test_result = queue.get() debug( "runner.run(): received proto test result: {}". format(str(proto_test_result)), 3, ) result.addProtoTestResult(proto_test_result) if result.shouldStop: debug("runner.run(): shouldStop encountered, breaking", 3) abort = True break if abort: break pool.close() pool.join() result.stopTestRun() removeResult(result) return result
def run(suite, stream, args): """ Run the given test case or test suite with the specified arguments. Any args.stream passed in will be wrapped in a GreenStream """ if not issubclass(GreenStream, type(stream)): stream = GreenStream(stream) result = GreenTestResult(args, stream) # Note: Catching SIGINT isn't supported by Python on windows (python # "WONTFIX" issue 18040) installHandler() registerResult(result) with warnings.catch_warnings(): if args.warnings: # if args.warnings is set, use it to filter all the warnings warnings.simplefilter(args.warnings) # if the filter is 'default' or 'always', special-case the # warnings from the deprecated unittest methods to show them # no more than once per module, because they can be fairly # noisy. The -Wd and -Wa flags can be used to bypass this # only when args.warnings is None. if args.warnings in ['default', 'always']: warnings.filterwarnings('module', category=DeprecationWarning, message='Please use assert\w+ instead.') result.startTestRun() tests = toProtoTestList(suite) pool = LoggingDaemonlessPool(processes=args.subprocesses or None) if tests: async_responses = [] for index, test in enumerate(tests): if args.run_coverage: coverage_number = index + 1 else: coverage_number = None async_responses.append(pool.apply_async( poolRunner, (test.dotted_name, coverage_number, args.omit_patterns))) pool.close() for test, async_response in zip(tests, async_responses): # Prints out the white 'processing...' version of the output result.startTest(test) # This blocks until the worker who is processing this # particular test actually finishes try: result.addProtoTestResult(async_response.get()) except KeyboardInterrupt: # pragma: no cover result.shouldStop = True if result.shouldStop: break pool.terminate() pool.join() result.stopTestRun() removeResult(result) return result