Best Python code snippet using yandex-tank
tankcore.py
Source:tankcore.py  
...329        logger.debug("Collecting artifacts")330        logger.info("Artifacts dir: %s", self.artifacts_dir)331        for filename, keep in self.artifact_files.items():332            try:333                self.__collect_file(filename, keep)334            except Exception as ex:335                logger.warn("Failed to collect file %s: %s", filename, ex)336    def get_option(self, section, option, default=None):337        """338        `Get` an option from option storage339        and `set` if default specified.340        """341        if not self.config.config.has_section(section):342            logger.debug("No section '%s', adding", section)343            self.config.config.add_section(section)344        try:345            value = self.config.config.get(section, option).strip()346        except ConfigParser.NoOptionError as ex:347            if default is not None:348                default = str(default)349                self.config.config.set(section, option, default)350                self.config.flush()351                value = default.strip()352            else:353                logger.warn(354                    "Mandatory option %s was not found in section %s", option,355                    section)356                raise ex357        if len(value) > 1 and value[0] == '`' and value[-1] == '`':358            logger.debug("Expanding shell option %s", value)359            retcode, stdout, stderr = execute(value[1:-1], True, 0.1, True)360            if retcode or stderr:361                raise ValueError(362                    "Error expanding option %s, RC: %s" % (value, retcode))363            value = stdout.strip()364        return value365    def set_option(self, section, option, value):366        """367        Set an option in storage368        """369        if not self.config.config.has_section(section):370            self.config.config.add_section(section)371        self.config.config.set(section, option, value)372        self.config.flush()373    def get_plugin_of_type(self, plugin_class):374        """375        Retrieve a plugin of desired class, KeyError raised otherwise376        """377        logger.debug("Searching for plugin: %s", plugin_class)378        matches = [plugin for plugin in self.plugins.values() if isinstance(plugin, plugin_class)]379        if len(matches) > 0:380            if len(matches) > 1:381                logger.debug(382                    "More then one plugin of type %s found. Using first one.",383                    plugin_class)384            return matches[-1]385        else:386            raise KeyError("Requested plugin type not found: %s" % plugin_class)387    def get_jobno(self, plugin_name='plugin_lunapark'):388        uploader_plugin = self.plugins[plugin_name]389        return uploader_plugin.lp_job.number390    def __collect_file(self, filename, keep_original=False):391        """392        Move or copy single file to artifacts dir393        """394        dest = self.artifacts_dir + '/' + os.path.basename(filename)395        logger.debug("Collecting file: %s to %s", filename, dest)396        if not filename or not os.path.exists(filename):397            logger.warning("File not found to collect: %s", filename)398            return399        if os.path.exists(dest):400            # FIXME: 3 find a way to store artifacts anyway401            logger.warning("File already exists: %s", dest)402            return403        if keep_original:404            shutil.copy(filename, self.artifacts_dir)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
