Best Python code snippet using avocado_python
__init__.py
Source:__init__.py
...68 key_type=list,69 default=[],70 help_msg=help_msg)71 help_msg = 'Base directory for Avocado tests and auxiliary data'72 default = prepend_base_path('/var/lib/avocado')73 stgs.register_option(section='datadir.paths',74 key='base_dir',75 key_type=prepend_base_path,76 default=default,77 help_msg=help_msg)78 help_msg = 'Test directory for Avocado tests'79 default = prepend_base_path('/usr/share/doc/avocado/tests')80 stgs.register_option(section='datadir.paths',81 key='test_dir',82 key_type=prepend_base_path,83 default=default,84 help_msg=help_msg)85 help_msg = 'Data directory for Avocado'86 default = prepend_base_path('/var/lib/avocado/data')87 stgs.register_option(section='datadir.paths',88 key='data_dir',89 key_type=prepend_base_path,90 default=default,91 help_msg=help_msg)92 help_msg = 'Logs directory for Avocado'93 default = prepend_base_path('~/avocado/job-results')94 stgs.register_option(section='datadir.paths',95 key='logs_dir',96 key_type=prepend_base_path,97 default=default,98 help_msg=help_msg)99 help_msg = ('The amount of time to wait after a test has reported '100 'status but the test process has not finished')101 stgs.register_option(section='runner.timeout',102 key='process_alive',103 key_type=int,104 help_msg=help_msg,105 default=60)106 help_msg = ('The amount of to wait for a test status after the '107 'process has been noticed to be dead')...
sysinfo.py
Source:sysinfo.py
...71 key_type=bool,72 help_msg=help_msg)73 help_msg = ('File with list of commands that will be executed and '74 'have their output collected')75 default = prepend_base_path('etc/avocado/sysinfo/commands')76 settings.register_option(section='sysinfo.collectibles',77 key='commands',78 key_type=prepend_base_path,79 default=default,80 help_msg=help_msg)81 help_msg = ('File with list of commands that will be executed and '82 'have their output collected, in case of failed test')83 default = prepend_base_path('etc/avocado/sysinfo/fail_commands')84 settings.register_option(section='sysinfo.collectibles',85 key='fail_commands',86 key_type=prepend_base_path,87 default=default,88 help_msg=help_msg)89 help_msg = 'File with list of files that will be collected verbatim'90 default = prepend_base_path('etc/avocado/sysinfo/files')91 settings.register_option(section='sysinfo.collectibles',92 key='files',93 key_type=prepend_base_path,94 default=default,95 help_msg=help_msg)96 help_msg = ('File with list of files that will be collected verbatim'97 ', in case of failed test')98 default = prepend_base_path('etc/avocado/sysinfo/fail_files')99 settings.register_option(section='sysinfo.collectibles',100 key='fail_files',101 key_type=prepend_base_path,102 default=default,103 help_msg=help_msg)104 help_msg = ('File with list of commands that will run alongside the '105 'job/test')106 default = prepend_base_path('etc/avocado/sysinfo/profilers')107 settings.register_option(section='sysinfo.collectibles',108 key='profilers',109 key_type=prepend_base_path,110 default=default,111 help_msg=help_msg)112class SysInfoJob(JobPreTests, JobPostTests):113 name = 'sysinfo'114 description = 'Collects system information before/after the job is run'115 def __init__(self, config):116 self.sysinfo = None117 self.sysinfo_enabled = config.get('sysinfo.collect.enabled')118 def _init_sysinfo(self, job_logdir):119 if self.sysinfo is None:120 basedir = path.init_dir(job_logdir, 'sysinfo')...
jobscripts.py
Source:jobscripts.py
1import os2from avocado.core.output import LOG_UI3from avocado.core.plugin_interfaces import Init, JobPost, JobPre4from avocado.core.settings import settings5from avocado.core.utils import prepend_base_path6from avocado.utils import process7class JobScriptsInit(Init):8 name = 'jobscripts-init'9 description = 'Jobscripts plugin initialization'10 def initialize(self):11 help_msg = 'Warn if configured (or default) directory does not exist'12 settings.register_option(section='plugins.jobscripts',13 key='warn_non_existing_dir',14 key_type=bool,15 default=False,16 help_msg=help_msg)17 help_msg = 'Warn if any script run return non-zero status'18 settings.register_option(section='plugins.jobscripts',19 key='warn_non_zero_status',20 key_type=bool,21 default=True,22 help_msg=help_msg)23 help_msg = 'Directory with scripts to be executed before a job is run'24 default = '/etc/avocado/scripts/job/pre.d/'25 settings.register_option(section='plugins.jobscripts',26 key='pre',27 key_type=prepend_base_path,28 help_msg=help_msg,29 default=default)30 help_msg = 'Directory with scripts to be executed after a job is run'31 default = '/etc/avocado/scripts/job/post.d/'32 settings.register_option(section='plugins.jobscripts',33 key='post',34 key_type=prepend_base_path,35 help_msg=help_msg,36 default=default)37class JobScripts(JobPre, JobPost):38 name = 'jobscripts'39 description = 'Runs scripts before/after the job is run'40 def _run_scripts(self, kind, scripts_dir, job):41 config = job.config42 if not os.path.isdir(scripts_dir):43 if config.get('plugins.jobscripts.warn_non_existing_dir'):44 LOG_UI.error("Directory configured to hold %s-job scripts "45 "has not been found: %s", kind, scripts_dir)46 return47 dir_list = os.listdir(scripts_dir)48 scripts = [os.path.join(scripts_dir, f) for f in dir_list]49 scripts = [f for f in scripts50 if os.access(f, os.R_OK | os.X_OK)]51 scripts.sort()52 if not scripts:53 return54 env = self._job_to_environment_variables(job)55 non_zero_namespace = 'plugins.jobscripts.warn_non_zero_status'56 warn_non_zero_status = config.get(non_zero_namespace)57 for script in scripts:58 result = process.run(script, ignore_status=True, env=env)59 if (result.exit_status != 0) and warn_non_zero_status:60 LOG_UI.error('%s job script "%s" exited with status "%i"',61 kind.capitalize(), script, result.exit_status)62 @staticmethod63 def _job_to_environment_variables(job):64 env = {}65 env['AVOCADO_JOB_UNIQUE_ID'] = job.unique_id66 env['AVOCADO_JOB_STATUS'] = job.status67 if job.logdir is not None:68 env['AVOCADO_JOB_LOGDIR'] = job.logdir69 return env70 def pre(self, job):71 path = job.config.get('plugins.jobscripts.pre')72 self._run_scripts('pre', path, job)73 def post(self, job):74 path = job.config.get('plugins.jobscripts.post')...
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!!