Esempio n. 1
0
    def start(self):
        """Start coverage before the test suite."""
        # cover_omit is a ',' separated list if provided
        self.omit = unshell_list(self.options.cover_omit)
        self.include = unshell_list(self.options.cover_omit)

        self.coverage = self.covpkg.coverage(
            config_file = self.options.cover_rcfile,
            data_suffix = bool(self.options.cover_parallel_mode),
            cover_pylib = self.options.cover_pylib,
            timid = self.options.cover_timid,
            branch = self.options.cover_branch,
            include = self.include,
            omit = self.omit,
        )

        self.coverage.start()
Esempio n. 2
0
    def configure(self, options, conf):
        """
        Configure plugin.
        """
        try:
            self.status.pop('active')
        except KeyError:
            pass
        super(Coverage, self).configure(options, conf)
        if self.enabled:
            try:
                import coverage
                if not hasattr(coverage, 'coverage'):
                    raise ImportError("Unable to import coverage module")
            except ImportError:
                log.error("Coverage not available: "
                          "unable to import coverage module")
                self.enabled = False
                return
        self.conf = conf
        self.coverErase = options.cover_erase
        self.coverTests = options.cover_tests
        self.coverPackages = []
        if options.cover_packages:
            if isinstance(options.cover_packages, (list, tuple)):
                cover_packages = options.cover_packages
            else:
                cover_packages = [options.cover_packages]
            for pkgs in [tolist(x) for x in cover_packages]:
                self.coverPackages.extend(pkgs)
        self.coverInclusive = options.cover_inclusive
        if self.coverPackages:
            log.info("Coverage report will include only packages: %s",
                     self.coverPackages)
        self.coverHtmlDir = None
        if options.cover_html:
            self.coverHtmlDir = options.cover_html_dir
            log.debug('Will put HTML coverage report in %s', self.coverHtmlDir)
        self.coverBranches = options.cover_branches
        self.coverXmlFile = None
        if options.cover_min_percentage:
            self.coverMinPercentage = int(options.cover_min_percentage.rstrip('%'))
        if options.cover_xml:
            self.coverXmlFile = options.cover_xml_file
            log.debug('Will put XML coverage report in %s', self.coverXmlFile)
        if self.enabled:
            self.status['active'] = True
            from coverage.cmdline import unshell_list
            # Build the list of file patterns to omit from the coverage report
            omit_patterns = unshell_list(options.omit_cover) if options.omit_cover else None
            self.coverInstance = coverage.coverage(auto_data=False,
                branch=self.coverBranches, data_suffix=conf.worker,
                source=self.coverPackages, omit=omit_patterns)
            self.coverInstance._warn_no_data = False
            self.coverInstance.is_worker = conf.worker
            self.coverInstance.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')

            log.debug("Coverage begin")
            self.skipModules = sys.modules.keys()[:]
            if self.coverErase:
                log.debug("Clearing previously collected coverage statistics")
                self.coverInstance.combine()
                self.coverInstance.erase()

            if not self.coverInstance.is_worker:
                self.coverInstance.load()
                self.coverInstance.start()