'Setup a Galaxy server for functional test (if needed).
Configuration options can be specified as attributes on the supplied
```config_object``` (defaults to self).'

def setup(self, config_object=None):

    if (config_object is None):
        config_object = self
    self.external_galaxy = os.environ.get('GALAXY_TEST_EXTERNAL', None)
    self.galaxy_test_tmp_dir = get_galaxy_test_tmp_dir()
    self.temp_directories.append(self.galaxy_test_tmp_dir)
    testing_shed_tools = getattr(config_object, 'testing_shed_tools', False)
    if getattr(config_object, 'framework_tool_and_types', False):
        default_tool_conf = FRAMEWORK_SAMPLE_TOOLS_CONF
        datatypes_conf_override = FRAMEWORK_DATATYPES_CONF
    else:
        default_tool_conf = getattr(config_object, 'default_tool_conf', None)
        datatypes_conf_override = getattr(config_object, 'datatypes_conf_override', None)
    if (self.external_galaxy is None):
        tempdir = tempfile.mkdtemp(dir=self.galaxy_test_tmp_dir)
        galaxy_db_path = database_files_path(tempdir)
        galaxy_config = getattr(config_object, 'galaxy_config', None)
        if hasattr(galaxy_config, '__call__'):
            galaxy_config = galaxy_config()
        if (galaxy_config is None):
            setup_galaxy_config_kwds = dict(use_test_file_dir=(not testing_shed_tools), default_install_db_merged=True, default_tool_conf=default_tool_conf, datatypes_conf=datatypes_conf_override)
            galaxy_config = setup_galaxy_config(galaxy_db_path, **setup_galaxy_config_kwds)
            handle_galaxy_config_kwds = getattr(config_object, 'handle_galaxy_config_kwds', None)
            if (handle_galaxy_config_kwds is not None):
                handle_galaxy_config_kwds(galaxy_config)
        self.app = build_galaxy_app(galaxy_config)
        server_wrapper = launch_server(self.app, buildapp.app_factory, galaxy_config, config_object=config_object)
        self.server_wrappers.append(server_wrapper)
        log.info(('Functional    tests    will    be    run    against    external    Galaxy    server    %s:%s' % (server_wrapper.host, server_wrapper.port)))
    else:
        log.info(('Functional    tests    will    be    run    against    test    managed    Galaxy    server    %s' % self.external_galaxy))
        ensure_test_file_dir_set()
