Exemplo n.º 1
0
    def handleDir(self, event):
        """Run load_tests in packages.

        If a package itself matches the test file pattern, run
        load_tests in its __init__.py, and stop default test
        discovery for that package.

        """
        if self._loading:
            return

        if (self._match(event.name, event.pattern) and
            util.ispackage(event.path)):
            name = util.name_from_path(event.path)
            module = util.module_from_name(name)

            load_tests = getattr(module, 'load_tests', None)
            if not load_tests:
                return
            self._loading = True
            try:
                suite = event.loader.suiteClass()
                try:
                    suite = load_tests(event.loader, suite, event.pattern)
                except Exception as exc:
                    log.exception(
                        "Failed to load tests from %s via load_tests", module)
                    suite.addTest(
                        event.loader.failedLoadTests(module.__name__, exc))

                event.handled = True
                return suite
            finally:
                self._loading = False
Exemplo n.º 2
0
    def _find_tests_in_dir(self, event, full_path, top_level):
        log.debug("find in dir %s (%s)", full_path, top_level)

        dirname = os.path.basename(full_path)
        pattern = self.session.testFilePattern

        evt = events.HandleFileEvent(
            event.loader, dirname, full_path, pattern, top_level)
        result = self.session.hooks.handleDir(evt)
        if evt.extraTests:
            for test in evt.extraTests:
                yield test
        if evt.handled:
            if result:
                yield result
            return

        evt = events.MatchPathEvent(dirname, full_path, pattern)
        result = self.session.hooks.matchDirPath(evt)
        if evt.handled and not result:
            return

        for path in os.listdir(full_path):
            entry_path = os.path.join(full_path, path)
            if os.path.isfile(entry_path):
                for test in self._find_tests_in_file(
                    event, path, entry_path, top_level):
                    yield test
            elif os.path.isdir(entry_path):
                if ('test' in path.lower()
                    or util.ispackage(entry_path)
                    or path in self.session.libDirs):
                    for test in self._find_tests(event, entry_path, top_level):
                        yield test
Exemplo n.º 3
0
    def _find_tests_in_dir(self, event, full_path, top_level):
        log.debug("find in dir %s (%s)", full_path, top_level)

        dirname = os.path.basename(full_path)
        pattern = self.session.testFilePattern

        evt = events.HandleFileEvent(event.loader, dirname, full_path, pattern,
                                     top_level)
        result = self.session.hooks.handleDir(evt)
        if evt.extraTests:
            for test in evt.extraTests:
                yield test
        if evt.handled:
            if result:
                yield result
            return

        evt = events.MatchPathEvent(dirname, full_path, pattern)
        result = self.session.hooks.matchDirPath(evt)
        if evt.handled and not result:
            return

        for path in os.listdir(full_path):
            entry_path = os.path.join(full_path, path)
            if os.path.isfile(entry_path):
                for test in self._find_tests_in_file(event, path, entry_path,
                                                     top_level):
                    yield test
            elif os.path.isdir(entry_path):
                if ('test' in path.lower() or util.ispackage(entry_path)
                        or path in self.session.libDirs):
                    for test in self._find_tests(event, entry_path, top_level):
                        yield test
Exemplo n.º 4
0
 def _find_tests_in_dir(self, event, full_path, top_level):
     log.debug("find in dir %s (%s)", full_path, top_level)
     for path in os.listdir(full_path):
         entry_path = os.path.join(full_path, path)
         if os.path.isfile(entry_path):
             for test in self._find_tests_in_file(
                 event, path, entry_path, top_level):
                 yield test
         elif os.path.isdir(entry_path):
             # FIXME need a hook or config opt here to allow
             # plugins/config to add more dirnames to look in
             if ('test' in path.lower()
                 or util.ispackage(entry_path)
                 or path in self.session.libDirs):
                 for test in self._find_tests(event, entry_path, top_level):
                     yield test
Exemplo n.º 5
0
 def _find_tests_in_dir(self, event, full_path, top_level):
     if not os.path.isdir(full_path):
         return
     log.debug("find in dir %s (%s)", full_path, top_level)
     dir_handler = DirectoryHandler(self.session)
     for test in dir_handler.handle_dir(event, full_path, top_level):
         yield test
     if dir_handler.event_handled:
         return
     for path in os.listdir(full_path):
         entry_path = os.path.join(full_path, path)
         if os.path.isfile(entry_path):
             for test in self._find_tests_in_file(event, path, entry_path,
                                                  top_level):
                 yield test
         elif os.path.isdir(entry_path):
             if ('test' in path.lower() or util.ispackage(entry_path)
                     or path in self.session.libDirs):
                 for test in self._find_tests(event, entry_path, top_level):
                     yield test
Exemplo n.º 6
0
 def _find_tests_in_dir(self, event, full_path, top_level):
     if not os.path.isdir(full_path):
         return
     log.debug("find in dir %s (%s)", full_path, top_level)
     dir_handler = DirectoryHandler(self.session)
     for test in dir_handler.handle_dir(event, full_path, top_level):
         yield test
     if dir_handler.event_handled:
         return
     for path in os.listdir(full_path):
         entry_path = os.path.join(full_path, path)
         if os.path.isfile(entry_path):
             for test in self._find_tests_in_file(
                 event, path, entry_path, top_level):
                 yield test
         elif os.path.isdir(entry_path):
             if ('test' in path.lower()
                 or util.ispackage(entry_path)
                 or path in self.session.libDirs):
                 for test in self._find_tests(event, entry_path, top_level):
                     yield test