How to use after_run_once method in autotest

Best Python code snippet using autotest_python

test.py

Source:test.py Github

copy

Full Screen

...156 self.run_once_profiling(postprocess_profiled_run, *args, **dargs)157 else:158 self.before_run_once()159 self.run_once(*args, **dargs)160 self.after_run_once()161 for hook in self.after_iteration_hooks:162 hook(self)163 self.postprocess_iteration()164 self.analyze_perf_constraints(constraints)165 def execute(self, iterations=None, test_length=None, profile_only=None,166 _get_time=time.time, postprocess_profiled_run=None,167 constraints=(), *args, **dargs):168 """169 This is the basic execute method for the tests inherited from base_test.170 If you want to implement a benchmark test, it's better to implement171 the run_once function, to cope with the profiling infrastructure. For172 other tests, you can just override the default implementation.173 @param test_length: The minimum test length in seconds. We'll run the174 run_once function for a number of times large enough to cover the175 minimum test length.176 @param iterations: A number of iterations that we'll run the run_once177 function. This parameter is incompatible with test_length and will178 be silently ignored if you specify both.179 @param profile_only: If true run X iterations with profilers enabled.180 If false run X iterations and one with profiling if profiles are181 enabled. If None, default to the value of job.default_profile_only.182 @param _get_time: [time.time] Used for unit test time injection.183 @param postprocess_profiled_run: Run the postprocessing for the184 profiled run.185 """186 # For our special class of tests, the benchmarks, we don't want187 # profilers to run during the test iterations. Let's reserve only188 # the last iteration for profiling, if needed. So let's stop189 # all profilers if they are present and active.190 profilers = self.job.profilers191 if profilers.active():192 profilers.stop(self)193 if profile_only is None:194 profile_only = self.job.default_profile_only195 # If the user called this test in an odd way (specified both iterations196 # and test_length), let's warn them.197 if iterations and test_length:198 logging.info('Iterations parameter ignored (timed execution).')199 if test_length:200 test_start = _get_time()201 time_elapsed = 0202 timed_counter = 0203 logging.info('Test started. Minimum test length: %d s',204 test_length)205 while time_elapsed < test_length:206 timed_counter = timed_counter + 1207 if time_elapsed == 0:208 logging.info('Executing iteration %d', timed_counter)209 elif time_elapsed > 0:210 logging.info(211 'Executing iteration %d, time_elapsed %d s',212 timed_counter, time_elapsed)213 self._call_run_once(constraints, profile_only,214 postprocess_profiled_run, args, dargs)215 test_iteration_finish = _get_time()216 time_elapsed = test_iteration_finish - test_start217 logging.info('Test finished after %d iterations',218 timed_counter)219 logging.info('Time elapsed: %d s', time_elapsed)220 else:221 if iterations is None:222 iterations = 1223 logging.info('Test started. Number of iterations: %d', iterations)224 for self.iteration in xrange(1, iterations+1):225 logging.info('Executing iteration %d of %d', self.iteration,226 iterations)227 self._call_run_once(constraints, profile_only,228 postprocess_profiled_run, args, dargs)229 logging.info('Test finished after %d iterations.', iterations)230 if not profile_only:231 self.iteration += 1232 self.run_once_profiling(postprocess_profiled_run, *args, **dargs)233 # Do any postprocessing, normally extracting performance keyvals, etc234 self.postprocess()235 self.process_failed_constraints()236 def run_once_profiling(self, postprocess_profiled_run, *args, **dargs):237 profilers = self.job.profilers238 # Do a profiling run if necessary239 if profilers.present():240 self.drop_caches_between_iterations()241 profilers.before_start(self)242 self.before_run_once()243 profilers.start(self)244 print 'Profilers present. Profiling run started'245 try:246 self.run_once(*args, **dargs)247 # Priority to the run_once() argument over the attribute.248 postprocess_attribute = getattr(self,249 'postprocess_profiled_run',250 False)251 if (postprocess_profiled_run or252 (postprocess_profiled_run is None and253 postprocess_attribute)):254 self.postprocess_iteration()255 finally:256 profilers.stop(self)257 profilers.report(self)258 self.after_run_once()259 def postprocess(self):260 pass261 def postprocess_iteration(self):262 pass263 def cleanup(self):264 pass265 def before_run_once(self):266 """267 Override in tests that need it, will be called before any run_once()268 call including the profiling run (when it's called before starting269 the profilers).270 """271 pass272 def after_run_once(self):273 """274 Called after every run_once (including from a profiled run when it's275 called after stopping the profilers).276 """277 pass278 def _exec(self, args, dargs):279 self.job.logging.tee_redirect_debug_dir(self.debugdir,280 log_name=self.tagged_testname)281 try:282 if self.network_destabilizing:283 self.job.disable_warnings("NETWORK")284 # write out the test attributes into a keyval285 dargs = dargs.copy()286 run_cleanup = dargs.pop('run_cleanup', self.job.run_test_cleanup)...

Full Screen

Full Screen

platform_SecureEraseFile.py

Source:platform_SecureEraseFile.py Github

copy

Full Screen

...84 if len(glob.glob('/dev/mmcblk*')) == 0:85 raise error.TestNAError('Skipping test; no eMMC device found.')86 self.__test_and_verify_cleared('64K', 2)87 self.__test_and_verify_cleared('1M', 16)88 def after_run_once(self):89 if os.path.exists(TEST_PATH):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful