Best Python code snippet using avocado_python
journal.py
Source:journal.py
...38 Creates an instance of ResultJournal.39 :param job: an instance of :class:`avocado.core.job.Job`.40 """41 self.journal_initialized = False42 def _init_journal(self, logdir):43 self.journal_path = os.path.join(logdir, JOURNAL_FILENAME)44 self.journal = sqlite3.connect(self.journal_path)45 self.journal_cursor = self.journal.cursor()46 for table in SCHEMA:47 res = \48 self.journal_cursor.execute("PRAGMA table_info('%s')" % table)49 if res.fetchone() is None:50 self.journal_cursor.execute(SCHEMA[table])51 self.journal.commit()52 def lazy_init_journal(self, state):53 # lazy init because we need the toplevel logdir for the job54 if not self.journal_initialized:55 self._init_journal(state['job_logdir'])56 self._record_job_info(state)57 self.journal_initialized = True58 def _shutdown_journal(self):59 self.journal.close()60 def _record_job_info(self, state):61 res = self.journal_cursor.execute("SELECT unique_id FROM job_info")62 if res.fetchone() is None:63 sql = "INSERT INTO job_info (unique_id) VALUES (?)"64 self.journal_cursor.execute(sql, (state['job_unique_id'],))65 self.journal.commit()66 def _record_status(self, state, action):67 sql = "INSERT INTO test_journal (tag, time, action, status) " \68 "VALUES (?, ?, ?, ?)"69 # This shouldn't be required70 if action == "ENDED":71 status = state['status']72 else:73 status = None74 self.journal_cursor.execute(sql,75 (str(state['name']),76 datetime.datetime(1, 1,77 1).now().isoformat(),78 action,79 status))80 self.journal.commit()81 def pre_tests(self, job):82 pass83 def start_test(self, result, state):84 self.lazy_init_journal(state)85 self._record_status(state, "STARTED")86 def test_progress(self, progress=False):87 pass88 def end_test(self, result, state):89 self.lazy_init_journal(state)90 self._record_status(state, "ENDED")91 def post_tests(self, job):92 self._shutdown_journal()93class Journal(CLI):94 """95 Test journal96 """97 name = 'journal'98 description = "Journal options for the 'run' subcommand"99 def configure(self, parser):100 run_subcommand_parser = parser.subcommands.choices.get('run', None)101 if run_subcommand_parser is None:102 return103 self.parser = parser...
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!!