Beispiel #1
0
def import_session(rlog, session_export):
    ssn = session.Session()
    ssn.config = session_export['config']
    ssn.hooks = RecordingPluginInterface()
    ssn.verbosity = session_export['verbosity']
    ssn.startDir = session_export['startDir']
    ssn.topLevelDir = session_export['topLevelDir']
    ssn.prepareSysPath()
    loader_ = loader.PluggableTestLoader(ssn)
    ssn.testLoader = loader_
    result_ = result.PluggableTestResult(ssn)
    ssn.testResult = result_
    runner_ = runner.PluggableTestRunner(ssn)  # needed??
    ssn.testRunner = runner_
    # load and register plugins, forcing multiprocess to the end
    ssn.plugins = [
        plugin(session=ssn) for plugin in session_export['pluginClasses']
        if plugin is not MultiProcess
    ]
    rlog.debug("Plugins loaded: %s", ssn.plugins)

    for plugin in ssn.plugins:
        plugin.register()
        rlog.debug("Registered %s in subprocess", plugin)

    # instantiating the plugin will register it.
    ssn.plugins.append(MultiProcess(session=ssn))
    rlog.debug("Registered %s in subprocess", MultiProcess)
    ssn.plugins[-1].pluginsLoaded(events.PluginsLoadedEvent(ssn.plugins))
    return ssn
Beispiel #2
0
    def document(self, rst, plugin):
        ssn = session.Session()
        ssn.configClass = ssn.config = config = ConfigBucket()
        ssn.pluginargs = opts = OptBucket()
        plugin_name = plugin.__name__
        config = ssn.config
        obj = plugin(session=ssn)
        try:
            obj.pluginsLoaded(events.PluginsLoadedEvent([obj]))
        except AttributeError:
            pass

        # config options
        if config.vars:
            self.add_config(rst, config, plugin)

        # command-line options
        if opts.opts:
            self.headline(rst, u"Command-line options")
            for opt in opts:
                for line in opt.options():
                    rst.append(line, AD)
                rst.append("", AD)

        # class __doc__
        self.headline(rst, u"Plugin class reference: %s" % plugin_name)
        rst.append(u".. autoclass :: %s" % plugin_name, AD)
        rst.append(u"   :members:", AD)
        rst.append(u"", AD)
Beispiel #3
0
    def loadPlugins(self, modules=None, exclude=None):
        """Load plugins.

        :param modules: List of module names from which to load plugins.

        """
        # plugins set directly
        if modules is None:
            modules = []
        if exclude is None:
            exclude = []
        # plugins mentioned in config file(s)
        cfg = self.unittest
        more_plugins = cfg.as_list('plugins', [])
        cfg_exclude = cfg.as_list('exclude-plugins', [])
        exclude.extend(cfg_exclude)
        exclude = set(exclude)
        all_ = set(modules + more_plugins) - exclude
        log.debug("Loading plugin modules: %s", all_)
        for module in all_:
            self.loadPluginsFromModule(util.module_from_name(module))
        self.hooks.pluginsLoaded(events.PluginsLoadedEvent(self.plugins))