def run(self): catchbreak = self.unit_test.pop("catchbreak") if catchbreak: from unittest.signals import installHandler installHandler() # Before use the output, we save the original for reset in the end org_out = sys.stdout org_err = sys.stderr try: test_runner = TestRunner(**self.__dict__) if test_runner.exit_request is None: if self.is_django: from django.test.simple import DjangoTestSuiteRunner dtsr = DjangoTestSuiteRunner(**self.unit_test) dtsr.setup_test_environment() old_config = dtsr.setup_databases() test_runner.run(self.test_list) dtsr.teardown_databases(old_config) dtsr.teardown_test_environment() else: test_runner.run(self.test_list) except Exception: print_exception() finally: # Return the output sys.stdout = org_out sys.stderr = org_err if isinstance(test_runner.exit_request, int): sys.exit(test_runner.exit_request)
def runTests(self): try: if self.catchbreak and installHandler: installHandler() except AttributeError: pass # does not have catchbreak attribute if self.testRunner is None: self.testRunner = DataTestRunner if isinstance(self.testRunner, type): try: kwds = ['verbosity', 'failfast', 'buffer', 'warnings', 'ignore'] kwds = [attr for attr in kwds if hasattr(self, attr)] kwds = dict((attr, getattr(self, attr)) for attr in kwds) testRunner = self.testRunner(**kwds) except TypeError: if 'warnings' in kwds: del kwds['warnings'] testRunner = self.testRunner(**kwds) else: # assumed to be a TestRunner instance testRunner = self.testRunner self.result = testRunner.run(self.test) if self.exit: _sys.exit(not self.result.wasSuccessful())
def runTests(self): try: if self.catchbreak and installHandler: installHandler() except AttributeError: pass # does not have catchbreak attribute if self.testRunner is None: self.testRunner = DataTestRunner if isinstance(self.testRunner, type): try: kwds = [ 'verbosity', 'failfast', 'buffer', 'warnings', 'ignore' ] kwds = [attr for attr in kwds if hasattr(self, attr)] kwds = dict((attr, getattr(self, attr)) for attr in kwds) testRunner = self.testRunner(**kwds) except TypeError: if 'warnings' in kwds: del kwds['warnings'] testRunner = self.testRunner(**kwds) else: # assumed to be a TestRunner instance testRunner = self.testRunner self.result = testRunner.run(self.test) if self.exit: _sys.exit(not self.result.wasSuccessful())
def main() -> None: args = parse_args() suite = defaultTestLoader.discover(_tests_, top_level_dir=_parent_, pattern=args.pattern) runner = TextTestRunner( verbosity=args.verbosity, failfast=args.fail, buffer=args.buffer, ) installHandler() runner.run(suite)
def main() -> int: args = _parse_args() suite = defaultTestLoader.discover( str(_TESTS), top_level_dir=str(_TOP_LV.parent), pattern=args.pattern ) runner = TextTestRunner( verbosity=args.verbosity, failfast=args.fail, buffer=args.buffer, ) installHandler() r = runner.run(suite) return not r.wasSuccessful()
def main() -> int: args = _parse_args() suite = defaultTestLoader.discover(normcase(_TESTS), top_level_dir=normcase(_ROOT), pattern="*.py") names = {*_names(args.paths)} tests = (test for test in _tests(suite) if not names or test.__module__ in names) runner = TextTestRunner( verbosity=args.verbosity, failfast=args.fail, buffer=args.buffer, ) installHandler() r = runner.run(TestSuite(tests)) return not r.wasSuccessful()
def __call__(self, test): # Executed in child process kwargs = self.runner_args # Force recording of output in a buffer (it will be printed out # by the parent). kwargs["stream"] = StringIO() runner = self.runner_cls(**kwargs) result = runner._makeResult() # Avoid child tracebacks when Ctrl-C is pressed. signals.installHandler() signals.registerResult(result) result.failfast = runner.failfast result.buffer = runner.buffer with self.cleanup_object(test): test(result) # HACK as cStringIO.StringIO isn't picklable in 2.x result.stream = _FakeStringIO(result.stream.getvalue()) return _MinimalResult(result)
def __call__(self, test): # Executed in child process kwargs = self.runner_args # Force recording of output in a buffer (it will be printed out # by the parent). kwargs['stream'] = StringIO() runner = self.runner_cls(**kwargs) result = runner._makeResult() # Avoid child tracebacks when Ctrl-C is pressed. signals.installHandler() signals.registerResult(result) result.failfast = runner.failfast result.buffer = runner.buffer with self.cleanup_object(test): test(result) # HACK as cStringIO.StringIO isn't picklable in 2.x result.stream = _FakeStringIO(result.stream.getvalue()) return _MinimalResult(result, test.id())
def runTests(self): if self.catchbreak: signals.installHandler() if self.testRunner is None: self.testRunner = runner.ParallelRunner if isinstance(self.testRunner, type): try: testRunner = self.testRunner(verbosity=self.verbosity, failfast=self.failfast, warnings=self.warnings) except TypeError: # didn't accept the verbosity, buffer or failfast arguments testRunner = self.testRunner() else: # it is assumed to be a TestRunner instance testRunner = self.testRunner result = testRunner.run(self.test) if self.exit: sys.exit(not result.wasSuccessful())
def runTests(self): if self.catchbreak: installHandler() if self.testRunner is None: self.testRunner = runner.TextTestRunner if isinstance(self.testRunner, (type, types.ClassType)): try: testRunner = self.testRunner(verbosity=self.verbosity, failfast=self.failfast, buffer=self.buffer) except TypeError: # didn't accept the verbosity, buffer or failfast arguments testRunner = self.testRunner() else: # it is assumed to be a TestRunner instance testRunner = self.testRunner self.result = testRunner.run(self.test) if self.exit: sys.exit(not self.result.wasSuccessful())
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
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 runtests(): args, commands = ARGS.parse_args() if args.coverage and coverage is None: URL = "bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py" print( textwrap.dedent(""" coverage package is not installed. To install coverage3 for Python 3, you need: - Setuptools (https://pypi.python.org/pypi/setuptools) What worked for me: - download {0} * curl -O https://{0} - python3 ez_setup.py - python3 -m easy_install coverage """.format(URL)).strip()) sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {0}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = args.pattern else: includes = args.pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.coverage: cov = coverage.coverage( branch=True, source=['asyncio'], ) cov.start() finder = TestsFinder(args.testsdir, includes, excludes) logger = logging.getLogger() if v == 0: logger.setLevel(logging.CRITICAL) elif v == 1: logger.setLevel(logging.ERROR) elif v == 2: logger.setLevel(logging.WARNING) elif v == 3: logger.setLevel(logging.INFO) elif v >= 4: logger.setLevel(logging.DEBUG) if catchbreak: installHandler() try: if args.forever: while True: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{0}/htmlcov/index.html".format(here))
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 runtests(): args = ARGS.parse_args() if args.coverage and coverage is None: URL = "bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py" print(textwrap.dedent(""" coverage package is not installed. To install coverage3 for Python 3, you need: - Setuptools (https://pypi.python.org/pypi/setuptools) What worked for me: - download {0} * curl -O https://{0} - python3 ez_setup.py - python3 -m easy_install coverage """.format(URL)).strip()) sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = args.pattern else: includes = args.pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.coverage: cov = coverage.coverage(branch=True, source=['aiozmq'], ) cov.start() finder = TestsFinder(args.testsdir, includes, excludes, verbose=args.verbose) logger = logging.getLogger() if v == 0: logger.setLevel(logging.CRITICAL) elif v == 1: logger.setLevel(logging.ERROR) elif v == 2: logger.setLevel(logging.WARNING) elif v == 3: logger.setLevel(logging.INFO) elif v >= 4: logger.setLevel(logging.DEBUG) if catchbreak: installHandler() try: if args.forever: while True: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast, warnings="always").run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast, warnings="always").run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() if os.path.exists('htmlcov'): shutil.rmtree('htmlcov') cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{}/htmlcov/index.html".format(here))
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 runtests(): args, pattern = ARGS.parse_args() if args.coverage and coverage is None: URL = "bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py" print( textwrap.dedent(""" coverage package is not installed. To install coverage3 for Python 3, you need: - Setuptools (https://pypi.python.org/pypi/setuptools) What worked for me: - download {0} * curl -O https://{0} - python3 ez_setup.py - python3 -m easy_install coverage """.format(URL)).strip()) sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {0}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = pattern else: includes = pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.monkey_patch: print("Enable eventlet monkey patching of the Python standard library") import eventlet eventlet.monkey_patch() if args.coverage: cov = coverage.coverage( branch=True, source=['asyncio'], ) cov.start() logger = logging.getLogger() if v == 0: level = logging.CRITICAL elif v == 1: level = logging.ERROR elif v == 2: level = logging.WARNING elif v == 3: level = logging.INFO elif v >= 4: level = logging.DEBUG logging.basicConfig(level=level) finder = TestsFinder(args.testsdir, includes, excludes) if catchbreak: installHandler() import tests if hasattr(tests.asyncio, 'coroutines'): debug = tests.asyncio.coroutines._DEBUG else: # Tulip <= 3.4.1 debug = tests.asyncio.tasks._DEBUG if debug: print("Run tests in debug mode") else: print("Run tests in release mode") sys.stdout.flush() try: if args.forever: while True: tests = finder.load_tests() if args.randomize: randomize_tests(tests, args.seed) result = runner_factory(verbosity=v, failfast=failfast).run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() if args.randomize: randomize_tests(tests, args.seed) result = runner_factory(verbosity=v, failfast=failfast).run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{0}/htmlcov/index.html".format(here))
def runtests(): args = ARGS.parse_args() if args.aiodebug: os.environ['PYTHONASYNCIODEBUG'] = '1' if args.coverage and coverage is None: print("Coverage package is not installed.") print("Please execute 'pip3 install coverage'") sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = args.pattern else: includes = args.pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.coverage: cov = coverage.coverage(branch=True, source=['aiopg'], ) cov.start() finder = TestsFinder(args.testsdir, includes, excludes, verbose=args.verbose) logger = logging.getLogger() if v == 0: logger.setLevel(logging.CRITICAL) elif v == 1: logger.setLevel(logging.ERROR) elif v == 2: logger.setLevel(logging.WARNING) elif v == 3: logger.setLevel(logging.INFO) elif v >= 4: logger.setLevel(logging.DEBUG) if catchbreak: installHandler() try: if args.forever: while True: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() if os.path.exists('htmlcov'): shutil.rmtree('htmlcov') cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{}/htmlcov/index.html".format(here))
def runtests(): args, pattern = ARGS.parse_args() if args.coverage and coverage is None: URL = "bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py" print(textwrap.dedent(""" coverage package is not installed. To install coverage3 for Python 3, you need: - Setuptools (https://pypi.python.org/pypi/setuptools) What worked for me: - download {0} * curl -O https://{0} - python3 ez_setup.py - python3 -m easy_install coverage """.format(URL)).strip()) sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {0}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = pattern else: includes = pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast if args.coverage: cov = coverage.coverage(branch=True, source=['asyncio'], ) cov.start() logger = logging.getLogger() if v == 0: level = logging.CRITICAL elif v == 1: level = logging.ERROR elif v == 2: level = logging.WARNING elif v == 3: level = logging.INFO elif v >= 4: level = logging.DEBUG logging.basicConfig(level=level) finder = TestsFinder(args.testsdir, includes, excludes) if args.catchbreak: installHandler() import trollius.coroutines if trollius.coroutines._DEBUG: print("Run tests in debug mode") else: print("Run tests in release mode") try: tests = finder.load_tests() if args.forever: while True: result = _runtests(args, tests) if not result.wasSuccessful(): sys.exit(1) else: result = _runtests(args, tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{0}/htmlcov/index.html".format(here))
def runtests(): args, pattern = ARGS.parse_args() if args.coverage and coverage is None: URL = "bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py" print(textwrap.dedent(""" coverage package is not installed. To install coverage3 for Python 3, you need: - Setuptools (https://pypi.python.org/pypi/setuptools) What worked for me: - download {0} * curl -O https://{0} - python3 ez_setup.py - python3 -m easy_install coverage """.format(URL)).strip()) sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {0}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = pattern else: includes = pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.monkey_patch: print("Enable eventlet monkey patching of the Python standard library") import eventlet eventlet.monkey_patch() if args.coverage: cov = coverage.coverage(branch=True, source=['asyncio'], ) cov.start() logger = logging.getLogger() if v == 0: level = logging.CRITICAL elif v == 1: level = logging.ERROR elif v == 2: level = logging.WARNING elif v == 3: level = logging.INFO elif v >= 4: level = logging.DEBUG logging.basicConfig(level=level) finder = TestsFinder(args.testsdir, includes, excludes) if catchbreak: installHandler() import tests if hasattr(tests.asyncio, 'coroutines'): debug = tests.asyncio.coroutines._DEBUG else: # Tulip <= 3.4.1 debug = tests.asyncio.tasks._DEBUG if debug: print("Run tests in debug mode") else: print("Run tests in release mode") sys.stdout.flush() try: if args.forever: while True: tests = finder.load_tests() if args.randomize: randomize_tests(tests, args.seed) result = runner_factory(verbosity=v, failfast=failfast).run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() if args.randomize: randomize_tests(tests, args.seed) result = runner_factory(verbosity=v, failfast=failfast).run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{0}/htmlcov/index.html".format(here))
def runtests(): args = ARGS.parse_args() if args.aiodebug: os.environ['PYTHONASYNCIODEBUG'] = '1' if args.coverage and coverage is None: print("Coverage package is not installed.") print("Please execute 'pip3 install coverage'") sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print("Tests directory is not found: {}\n".format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = args.pattern else: includes = args.pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.coverage: cov = coverage.coverage( branch=True, source=['aiopg'], ) cov.start() finder = TestsFinder(args.testsdir, includes, excludes, verbose=args.verbose) logger = logging.getLogger() if v == 0: logger.setLevel(logging.CRITICAL) elif v == 1: logger.setLevel(logging.ERROR) elif v == 2: logger.setLevel(logging.WARNING) elif v == 3: logger.setLevel(logging.INFO) elif v >= 4: logger.setLevel(logging.DEBUG) if catchbreak: installHandler() try: if args.forever: while True: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() if os.path.exists('htmlcov'): shutil.rmtree('htmlcov') cov.html_report(directory='htmlcov') print("\nCoverage report:") cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print("\nFor html report:") print("open file://{}/htmlcov/index.html".format(here))
def runtests(): args = ARGS.parse_args() if args.coverage and coverage is None: URL = 'bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py' print(textwrap.dedent(''' coverage package is not installed. To install coverage3 for Python 3, you need: - Setuptools (https://pypi.python.org/pypi/setuptools) What worked for me: - download {0} * curl -O https://{0} - python3 ez_setup.py - python3 -m easy_install coverage '''.format(URL)).strip()) sys.exit(1) testsdir = os.path.abspath(args.testsdir) if not os.path.isdir(testsdir): print('Tests directory is not found: {}\n'.format(testsdir)) ARGS.print_help() return excludes = includes = [] if args.exclude: excludes = args.pattern else: includes = args.pattern v = 0 if args.quiet else args.verbose + 1 failfast = args.failfast catchbreak = args.catchbreak findleaks = args.findleaks runner_factory = TestRunner if findleaks else unittest.TextTestRunner if args.coverage: cov = coverage.coverage(branch=True, source=['asyncnsq'], ) cov.start() finder = TestsFinder(args.testsdir, includes, excludes, verbose=args.verbose) loglevels = ( logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG ) v = abs(v) if v >= len(loglevels): v = len(loglevels)-1 logging.basicConfig(level=loglevels[v]) if catchbreak: installHandler() try: if args.forever: while True: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) if not result.wasSuccessful(): sys.exit(1) else: tests = finder.load_tests() result = runner_factory(verbosity=v, failfast=failfast).run(tests) sys.exit(not result.wasSuccessful()) finally: if args.coverage: cov.stop() cov.save() if os.path.exists('htmlcov'): shutil.rmtree('htmlcov') cov.html_report(directory='htmlcov') print('\nCoverage report:') cov.report(show_missing=False) here = os.path.dirname(os.path.abspath(__file__)) print('\nFor html report:') print('open file://{}/htmlcov/index.html'.format(here))