Best Python code snippet using avocado_python
job.py
Source:job.py
...138 logdir = os.path.abspath(logdir)139 self.logdir = data_dir.create_job_logs_dir(logdir=logdir,140 unique_id=self.unique_id)141 if not (self.standalone or getattr(self.args, "dry_run", False)):142 self._update_latest_link()143 self.logfile = os.path.join(self.logdir, "job.log")144 idfile = os.path.join(self.logdir, "id")145 with open(idfile, 'w') as id_file_obj:146 id_file_obj.write("%s\n" % self.unique_id)147 def __start_job_logging(self):148 # Enable test logger149 fmt = ('%(asctime)s %(module)-16.16s L%(lineno)-.4d %('150 'levelname)-5.5s| %(message)s')151 test_handler = output.add_log_handler("avocado.test",152 logging.FileHandler,153 self.logfile, self.loglevel, fmt)154 root_logger = logging.getLogger()155 root_logger.addHandler(test_handler)156 root_logger.setLevel(self.loglevel)157 self.__logging_handlers[test_handler] = ["avocado.test", ""]158 # Add --store-logging-streams159 fmt = '%(asctime)s %(levelname)-5.5s| %(message)s'160 formatter = logging.Formatter(fmt=fmt, datefmt='%H:%M:%S')161 for name in getattr(self.args, "store_logging_stream", []):162 name = re.split(r'(?<!\\):', name, maxsplit=1)163 if len(name) == 1:164 name = name[0]165 level = logging.INFO166 else:167 level = (int(name[1]) if name[1].isdigit()168 else logging.getLevelName(name[1].upper()))169 name = name[0]170 try:171 logfile = os.path.join(self.logdir, name + "." +172 logging.getLevelName(level))173 handler = output.add_log_handler(name, logging.FileHandler,174 logfile, level, formatter)175 except ValueError, details:176 self.log.error("Failed to set log for --store-logging-stream "177 "%s:%s: %s.", name, level, details)178 else:179 self.__logging_handlers[handler] = [name]180 # Enable console loggers181 enabled_logs = getattr(self.args, "show", [])182 if ('test' in enabled_logs and183 'early' not in enabled_logs):184 self._stdout_stderr = sys.stdout, sys.stderr185 # Enable std{out,err} but redirect booth to stderr186 sys.stdout = STD_OUTPUT.stdout187 sys.stderr = STD_OUTPUT.stdout188 test_handler = output.add_log_handler("avocado.test",189 logging.StreamHandler,190 STD_OUTPUT.stdout,191 logging.DEBUG,192 fmt="%(message)s")193 root_logger.addHandler(test_handler)194 self.__logging_handlers[test_handler] = ["avocado.test", ""]195 def __stop_job_logging(self):196 if self._stdout_stderr:197 sys.stdout, sys.stderr = self._stdout_stderr198 for handler, loggers in self.__logging_handlers.iteritems():199 for logger in loggers:200 logging.getLogger(logger).removeHandler(handler)201 def _update_latest_link(self):202 """203 Update the latest job result symbolic link [avocado-logs-dir]/latest.204 """205 def soft_abort(msg):206 """ Only log the problem """207 logging.getLogger("avocado.test").warning("Unable to update the "208 "latest link: %s" % msg)209 basedir = os.path.dirname(self.logdir)210 basename = os.path.basename(self.logdir)211 proc_latest = os.path.join(basedir, "latest.%s" % os.getpid())212 latest = os.path.join(basedir, "latest")213 if os.path.exists(latest) and not os.path.islink(latest):214 soft_abort('"%s" already exists and is not a symlink' % latest)215 return...
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!!