Exemplo n.º 1
0
 def runTests(self):
     if self.catchbreak:
         installHandler()
     if self.testRunner is None:
         self.testRunner = runner.TextTestRunner
     if isinstance(self.testRunner, six.class_types):
         try:
             try:
                 testRunner = self.testRunner(verbosity=self.verbosity,
                                              failfast=self.failfast,
                                              buffer=self.buffer,
                                              tb_locals=self.tb_locals)
             except TypeError:
                 # didn't accept the tb_locals argument
                 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())
Exemplo n.º 2
0
 def runTests(self):
     if self.catchbreak:
         installHandler()
     if self.testRunner is None:
         self.testRunner = runner.TextTestRunner
     if isinstance(self.testRunner, six.class_types):
         try:
             try:
                 testRunner = self.testRunner(verbosity=self.verbosity,
                                              failfast=self.failfast,
                                              buffer=self.buffer,
                                              tb_locals=self.tb_locals)
             except TypeError:
                 # didn't accept the tb_locals argument
                 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())
Exemplo n.º 3
0
def runtests():
    args, pattern = ARGS.parse_args()

    if args.no_ssl:
        sys.modules['ssl'] = None

    if args.no_concurrent:
        sys.modules['concurrent'] = None

    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()

    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))