Exemple #1
0
    def run(self):
        cov = None
        if self.coverage:
            import coverage
            omit = ["/usr/*", "/*/tests/*"]
            cov = coverage.coverage(omit=omit)
            cov.erase()
            if not self._external_coverage:
                cov.start()

        import tests as testsmodule
        testsmodule.utils.clistate.regenerate_output = bool(
            self.regenerate_output)
        testsmodule.utils.clistate.use_coverage = bool(cov)
        testsmodule.utils.clistate.debug = bool(self.debug)
        testsmodule.setup_logging()
        testsmodule.setup_cli_imports()

        # This makes the test runner report results before exiting from ctrl-c
        unittest.installHandler()

        tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
        if self.only:
            newtests = []
            for suite1 in tests:
                for suite2 in suite1:
                    for testcase in suite2:
                        if self.only in str(testcase):
                            newtests.append(testcase)

            if not newtests:
                print("--only didn't find any tests")
                sys.exit(1)
            tests = unittest.TestSuite(newtests)
            print("Running only:")
            for test in newtests:
                print("%s" % test)
            print("")

        verbosity = 1
        if self.debug or self.testverbose or self._force_verbose:
            verbosity = 2
        t = unittest.TextTestRunner(verbosity=verbosity)

        try:
            result = t.run(tests)
        except KeyboardInterrupt:
            sys.exit(1)

        if cov:
            if self._external_coverage:
                cov.load()
            else:
                cov.stop()
                cov.save()

        err = int(bool(len(result.failures) > 0 or len(result.errors) > 0))
        if cov and not err:
            cov.report(show_missing=False)
        sys.exit(err)
Exemple #2
0
    def run(self):
        cov = None
        if self.coverage:
            import coverage
            omit = ["/usr/*", "/*/tests/*"]
            cov = coverage.coverage(omit=omit)
            cov.erase()
            if not self._external_coverage:
                cov.start()

        import tests as testsmodule
        testsmodule.utils.clistate.regenerate_output = bool(
                self.regenerate_output)
        testsmodule.utils.clistate.use_coverage = bool(cov)
        testsmodule.utils.clistate.debug = bool(self.debug)
        testsmodule.setup_logging()
        testsmodule.setup_cli_imports()

        # This makes the test runner report results before exiting from ctrl-c
        unittest.installHandler()

        tests = unittest.TestLoader().loadTestsFromNames(self._testfiles)
        if self.only:
            newtests = []
            for suite1 in tests:
                for suite2 in suite1:
                    for testcase in suite2:
                        if self.only in str(testcase):
                            newtests.append(testcase)

            if not newtests:
                print("--only didn't find any tests")
                sys.exit(1)
            tests = unittest.TestSuite(newtests)
            print("Running only:")
            for test in newtests:
                print("%s" % test)
            print("")

        verbosity = 1
        if self.debug or self.testverbose or self._force_verbose:
            verbosity = 2
        t = unittest.TextTestRunner(verbosity=verbosity)

        try:
            result = t.run(tests)
        except KeyboardInterrupt:
            sys.exit(1)

        if cov:
            if self._external_coverage:
                cov.load()
            else:
                cov.stop()
                cov.save()

        err = int(bool(len(result.failures) > 0 or
                       len(result.errors) > 0))
        if cov and not err:
            cov.report(show_missing=False)
        sys.exit(err)