コード例 #1
0
ファイル: scriptloader.py プロジェクト: whilp/scriptloader
    def loadTestsFromName(self, name, module=None, discovered=False,
            addr=None, loader=load_source):
        """Load tests from the entity with the given *name*.

        If *name* is a filename, attempt to load it using
        :func:`imp.load_source`. If that succeeds, search for a matching name in
        the loaded module.
        """
        if module or self.loadedTestsFromName or ":" not in name:
            return None

        if addr is None: # pragma: nocover
            addr = nose.selector.TestAddress(name, workingDir=self.loader.workingDir)
        path = addr.filename
        if not path:
            return None

        try:
            module = loader("module", path)
        except SyntaxError:
            return None

        name = addr.call
        log.debug("loaded tests from name %s at file %r", name, path)
        self.loadedTestsFromName = True
        return self.loader.loadTestsFromName(name, module=module,
            discovered=discovered)
コード例 #2
0
ファイル: scriptloader.py プロジェクト: whilp/scriptloader
    def loadTestsFromFile(self, filename, loader=load_source):
        """Load tests from *filename*.

        Attempt to load the file using :func:`imp.load_source`. If that
        succeeds, pass the loaded module to the :attr:`loader`
        :meth:`loadTestsFromModule`. If the file can't be loaded, return None
        so other plugins can try loading it.
        """
        name = inspect.getmodulename(filename)
        if not name:
            name = os.path.basename(filename)
        try:
            module = loader(name, filename)
            log.debug("loaded module %r from file %r", name, filename)
        except SyntaxError:
            return None

        return self.loader.loadTestsFromModule(module)