def test_returnIsLoadable(self): """ Results returned by toParallelTargets should be loadable by loadTargets(), even if they aren't directly loadable through a package relative to the current working directory. """ tests_dir = tempfile.mkdtemp(dir=self.tmpdir) # No __init__.py in the directory! fh = open(os.path.join(tests_dir, "test_not_in_pkg.py"), "w") fh.write( dedent( """ import unittest class A(unittest.TestCase): def testPass(self): pass """ ) ) fh.close() # Discover stuff suite = self.loader.loadTargets(".") # This should resolve it to the module that's not importable from here test = loader.toParallelTargets(suite, [])[0] self.loader.loadTargets(test)
def test_returnIsLoadable(self): """ Results returned by toParallelTargets should be loadable by loadTargets(), even if they aren't directly loadable through a package relative to the current working directory. """ tests_dir = tempfile.mkdtemp(dir=self.tmpdir) # No __init__.py in the directory! fh = open(os.path.join(tests_dir, "test_not_in_pkg.py"), "w") fh.write( dedent( """ import unittest class A(unittest.TestCase): def testPass(self): pass """ ) ) fh.close() # Discover stuff suite = loader.loadTargets(".") # This should resolve it to the module that's not importable from here test = loader.toParallelTargets(suite, [])[0] reloaded = loader.loadTargets(test)
def test_methods_with_no_constraints(self): """ toParallelTargets() returns only module names. """ class NormalTestCase(unittest.TestCase): def runTest(self): pass NormalTestCase.__module__ = self._fake_module_name targets = loader.toParallelTargets(NormalTestCase(), []) self.assertEqual(targets, [self._fake_module_name])
def test_methods_with_no_constraints(self): """ toParallelTargets() returns only module names. """ class NormalTestCase(unittest.TestCase): def runTest(self): pass NormalTestCase.__module__ = self._fake_module_name targets = loader.toParallelTargets(NormalTestCase(), []) self.assertEqual(targets, ["my_test_module"])
def test_methods_with_constraints(self): """ toParallelTargets() returns test names when constrained. """ class NormalTestCase(unittest.TestCase): def runTest(self): pass NormalTestCase.__module__ = self._fake_module_name full_name = "my_test_module.NormalTestCase.runTest" targets = loader.toParallelTargets(NormalTestCase(), [full_name]) self.assertEqual(targets, [full_name])
def test_filter_out_dot(self): """ toParallelTargets() correctly returns modules when '.' is in target list """ class NormalTestCase(unittest.TestCase): def runTest(self): pass class NormalTestCase2(unittest.TestCase): def runTest(self): pass NormalTestCase.__module__ = self._fake_module_name NormalTestCase2.__module__ = self._fake_module_name2 targets = loader.toParallelTargets([NormalTestCase(), NormalTestCase2()], ['.']) self.assertEqual(targets, ["my_test_module", "my_test_module2"])
def test_filter_out_dot(self): """ toParallelTargets() correctly returns modules when '.' is in target list """ class NormalTestCase(unittest.TestCase): def runTest(self): pass class NormalTestCase2(unittest.TestCase): def runTest(self): pass NormalTestCase.__module__ = self._fake_module_name NormalTestCase2.__module__ = self._fake_module_name2 targets = loader.toParallelTargets( [NormalTestCase(), NormalTestCase2()], ['.']) self.assertEqual(targets, ["my_test_module", "my_test_module2"])
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