How to use find_test_run_time_diff method in stestr

Best Python code snippet using stestr_python

subunit_trace.py

Source:subunit_trace.py Github

copy

Full Screen

...101 # offset102 for line in detail.as_text().split('\n'):103 line = line.encode('utf8')104 stream.write(" %s\n" % line)105def find_test_run_time_diff(test_id, run_time):106 times_db_path = os.path.join(os.path.join(os.getcwd(), '.testrepository'),107 'times.dbm')108 if os.path.isfile(times_db_path):109 try:110 test_times = dbm.open(times_db_path)111 except Exception:112 return False113 try:114 avg_runtime = float(test_times.get(str(test_id), False))115 except Exception:116 try:117 avg_runtime = float(test_times[str(test_id)])118 except Exception:119 avg_runtime = False120 if avg_runtime and avg_runtime > 0:121 run_time = float(run_time.rstrip('s'))122 perc_diff = ((run_time - avg_runtime) / avg_runtime) * 100123 return perc_diff124 return False125def show_outcome(stream, test, print_failures=False, failonly=False,126 enable_diff=False, threshold='0', abbreviate=False,127 enable_color=False):128 global RESULTS129 status = test['status']130 # TODO(sdague): ask lifeless why on this?131 if status == 'exists':132 return133 worker = find_worker(test)134 name = cleanup_test_name(test['id'])135 duration = get_duration(test['timestamps'])136 if worker not in RESULTS:137 RESULTS[worker] = []138 RESULTS[worker].append(test)139 # don't count the end of the return code as a fail140 if name == 'process-returncode':141 return142 for color in [colorizer.AnsiColorizer, colorizer.NullColorizer]:143 if not enable_color:144 color = colorizer.NullColorizer(stream)145 break146 if color.supported():147 color = color(stream)148 break149 if status == 'fail':150 FAILS.append(test)151 if abbreviate:152 color.write('F', 'red')153 else:154 stream.write('{%s} %s [%s] ... ' % (155 worker, name, duration))156 color.write('FAILED', 'red')157 stream.write('\n')158 if not print_failures:159 print_attachments(stream, test, all_channels=True)160 elif not failonly:161 if status == 'success':162 if abbreviate:163 color.write('.', 'green')164 else:165 out_string = '{%s} %s [%s' % (worker, name, duration)166 perc_diff = find_test_run_time_diff(test['id'], duration)167 if enable_diff:168 if perc_diff and abs(perc_diff) >= abs(float(threshold)):169 if perc_diff > 0:170 out_string = out_string + ' +%.2f%%' % perc_diff171 else:172 out_string = out_string + ' %.2f%%' % perc_diff173 stream.write(out_string + '] ... ')174 color.write('ok', 'green')175 stream.write('\n')176 print_attachments(stream, test)177 elif status == 'skip':178 if abbreviate:179 color.write('S', 'blue')180 else:...

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 stestr 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