Best Python code snippet using autotest_python
base_sysinfo.py
Source:base_sysinfo.py
...156 if not glob.glob(os.path.join(self.sysinfodir, "*")):157 return -1158 else:159 return len(glob.glob(os.path.join(self.sysinfodir, "boot.*")))160 def _get_boot_subdir(self, next=False):161 reboot_count = self._get_reboot_count()162 if next:163 reboot_count += 1164 if reboot_count < 1:165 return self.sysinfodir166 else:167 boot_dir = "boot.%d" % (reboot_count - 1)168 return os.path.join(self.sysinfodir, boot_dir)169 def _get_iteration_subdir(self, test, iteration):170 iter_dir = "iteration.%d" % iteration171 logdir = os.path.join(self._get_sysinfodir(test.outputdir), iter_dir)172 if not os.path.exists(logdir):173 os.mkdir(logdir)174 return logdir175 @log.log_and_ignore_errors("post-reboot sysinfo error:")176 def log_per_reboot_data(self):177 """ Logging hook called whenever a job starts, and again after178 any reboot. """179 logdir = self._get_boot_subdir(next=True)180 if not os.path.exists(logdir):181 os.mkdir(logdir)182 for log in (self.test_loggables | self.boot_loggables):183 log.run(logdir)184 # also log any installed packages185 installed_path = os.path.join(logdir, "installed_packages")186 installed_packages = "\n".join(package.list_all()) + "\n"187 utils.open_write_close(installed_path, installed_packages)188 @log.log_and_ignore_errors("pre-test sysinfo error:")189 def log_before_each_test(self, test):190 """ Logging hook called before a test starts. """191 self._installed_packages = package.list_all()192 if os.path.exists("/var/log/messages"):193 stat = os.stat("/var/log/messages")194 self._messages_size = stat.st_size195 self._messages_inode = stat.st_ino196 @log.log_and_ignore_errors("post-test sysinfo error:")197 def log_after_each_test(self, test):198 """ Logging hook called after a test finishs. """199 test_sysinfodir = self._get_sysinfodir(test.outputdir)200 # create a symlink in the test sysinfo dir to the current boot201 reboot_dir = self._get_boot_subdir()202 assert os.path.exists(reboot_dir)203 symlink_dest = os.path.join(test_sysinfodir, "reboot_current")204 symlink_src = utils.get_relative_path(reboot_dir,205 os.path.dirname(symlink_dest))206 try:207 os.symlink(symlink_src, symlink_dest)208 except Exception, e:209 raise Exception, '%s: whilst linking %s to %s' % (e, symlink_src,210 symlink_dest)211 # run all the standard logging commands212 for log in self.test_loggables:213 log.run(test_sysinfodir)214 # grab any new data from /var/log/messages215 self._log_messages(test_sysinfodir)...
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!!